Friday 25 May 2018

Switch Statement in Salesforce | Salesforce Summer ’18 Release Notes


Simplify Your Code with the Apex Switch Statement




Finally Swtich Statement is available in Salesforce with Summer 18.


Sample Code:-
public class  SwitchExample { 
    public static void testSwitchCase() {
        Integer i = 2;
        switch on i {
            when 1
            {
                System.debug('One------>');
            }
            when 2
            {
                System.debug('Two------->');
            }
            when else
            {
                System.debug('default----->');
            }
        }
    }
}
NOTE:- Please set the Apex code version as 43. 

 (This Image is from Salesforce documentation)


 Thanks
Amit Chaudhary

No comments:

Post a Comment