Of course, like all programming languages, Apex includes syntax to implement conditional logic, otherwise known as IF – THEN – ELSE logic.
The basic format for this type of code is the following:
if (Boolean_expression) Statement; else Statement;
Note that the Boolean must be within parentheses, even if it is a simple expression, and you need to have semi-colons to indicate the end of each statement in the conditional logic.
The form shown above includes a single statement for each condition. Normally, you create multiple statements for a condition, requiring the use of curly braces to group the statements, as in the following:
if (Boolean_expression){ statement; statement; statement; statement;} else { statement; statement;}
You can nest if statements, giving syntax similar to the following:
if (Location.Name == 'Toronto'){ Location.country__c = 'Canada'; } else if {(Location.Name == 'London'){ Location.country__c = 'United Kingdom'; } else { Location.country__c = 'United States'; }
18.116.51.134