Control Logic

This subsection describes how to control the flow of Apex code execution. It covers conditional statements, loops, exception statements, recursion, and asynchronous execution.

Conditional Statements

Conditional statements evaluate a Boolean condition and execute one code block if true, another if false. Listing 4.18 provides an example, defining a function that prints true if an Integer argument is greater than 100, false otherwise.

Listing 4.18 Conditional Statement Usage

void testValue(Integer value) {   if (value > 100) {    System.debug('true');  } else {    System.debug('false');  }}testValue(99);testValue(101);

In addition to this simple if, else structure, you can chain multiple conditional ...

Get Development with the Force.com Platform: Building Business Applications in the Cloud, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.