Activity Forums Salesforce® Discussions How to use Switch Clause in Apex as it is used in Java or C?

  • Abhinav

    Member
    April 14, 2016 at 8:24 am

    Apex does not support switch case statements.Use if else if .statements for this. However, Yes formula fields support case syntax but Apex doesn't.

  • Prafull

    Member
    April 14, 2016 at 8:33 am

    Hi Ajit,

    Apex doesn't support switch clause as of now.. Salesforce will release it next year... So instead of switch case you have to use else if condition..

    Thanks

  • Phil

    Member
    March 15, 2018 at 11:43 am

    Take a look at my response on https://developer.salesforce.com/forums/?id=906F000000090xKIAQ - this is a typical object-oriented approach. Note that switch statements are really non-OO, from a purist perspective.

  • Manish

    Member
    May 31, 2018 at 10:17 am

    Apex now supports Switch Statements (from Summer '18 Release):

    Full answer here : https://developer.salesforce.com/blogs/2018/05/summer18-rethink-trigger-logic-with-apex-switch.html

Log In to reply.

Popular Salesforce Blogs