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. 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----->');
}
}
}
}
(This Image is from Salesforce documentation)
Thanks
Amit Chaudhary
No comments:
Post a Comment