May 2019
Intermediate to advanced
546 pages
12h 41m
English
In the previous piece of code, you saw the nested if...else statement. If you always need to compare the same variable in your code block, you can use the 'switch' statement. You define a certain variable, and, depending on the value of that variable, the platform executes your block of code.
The syntax of a switch statement is as follows:
switch on expression { when value1 { // execute code block 1 } when value2 { // execute code block 2 } when value3 { // execute code block 3 } when else { // execute the default code block, this is optional }}
I've rewritten the if-else structure from Chapter 3, Declarative Automation, in a switch statement. It looks like this:
Integer iPlace = 2;String sMedalColor = '';switch on iPlace { when 1{ ...Read now
Unlock full access