Newer Version Available

This content describes an older version of this product. View Latest

For Loops

Apex supports three variations of the for loop:
  • The traditional for loop:
  • The list or set iteration for loop:
    where variable must be of the same primitive or sObject type as list_or_set.
  • The SOQL for loop:
    or
    Both variable and variable_list must be of the same sObject type as is returned by the soql_query.

Curly braces ({}) are required around a code_block only if the block contains more than one statement.

Note

Each is discussed further in the sections that follow.