Process Automation and Logic28% of the exam

Apex control flow, loops and collections

How if-else, switch and the five Apex loops execute, what break and continue do, how SOQL for loops chunk records, how lists, sets and maps behave while you iterate them, and how the safe navigation and null coalescing operators handle nulls.

Official exam objective
Given a scenario, assess how Apex control flow statements will execute and when to apply different control flow statements.

~7 min read · 8 practice questions ·

What the exam expects

  • Predict which branch of an if-else chain or switch on runs, including when else and null.
  • Choose among do-while, while, traditional for, list or set iteration and SOQL for loops, and predict how many times each body runs.
  • Tell break from continue and return in a loop.
  • Iterate lists, sets and maps safely, and pick the collection whose rules (order, duplicates, keys) fit the job.
  • Use the safe navigation (?.) and null coalescing (??) operators to avoid a NullPointerException.

Key terms: when else (the switch default block); do-while (tests its condition after the body); SOQL for loop (iterates query results in chunks); safe navigation (?. returns null instead of throwing); null coalescing (?? supplies a fallback for null).

Key facts

switch expression types
Detail
Integer, Long, sObject, String, Enum
switch fall-through
Detail
None; when else is optional and must be last
do-while
Detail
Body always runs at least once
while
Detail
Condition tested first; body may never run
Loop types
Detail
Five: do-while, while, for, list or set iteration, SOQL for
break / continue
Detail
Exits the entire loop / skips to the next iteration
SOQL for loop, list format
Detail
Body runs once per 200 records
Modifying a collection mid-iteration
Detail
Not supported; causes an error
Map String keys
Detail
Case-sensitive; an existing key is overwritten by put
?. on null
Detail
Returns null; right side not evaluated
Sources for this section (8)
  • When does a do-while body run even though its condition is false?
  • Why use the list format of a SOQL for loop when the loop body performs DML?
  • What happens when no `when` value matches and there is no `when else`?
  • Why would you choose a set over a list for a group of Ids?
  • What does `con.Account?.BillingCity` return when the contact has no account?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the Platform Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 21 lessons of the Platform Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (8 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the Platform Developer exam