O'Reilly logo

The Developer’s Guide to the Force.com Platform by Phil Choi, Andrew Fawcett, Glen Martin, Rick Greenwald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Apex Conditional Logic

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required