Apex Statement Types & Syntax
Just like any other programming language, an Apex Statement is simply any code that executes an action. A semicolon must end with all Apex Statements!
Types of Apex-Statement Usage: - Variable Assignments - If/Else Conditional Statements - Locking - DML (Data Manipulation Language) to insert, update, delete, etc. - Transactional Controls - Method Invoking - Exceptions Handling - Loops that include Do-while, While, For Use curly brackets { } to contain a single block of statements that are grouped to execute as one single statement.
if (true) { System.debug(1); //--> statement 1 of group 1 System.debug(2); //--> statement 2 of group 2 } else { System.debug(3); //--> statement 3 of group 2 System.debug(4); //--> statement 4 of group 2 }
If a block only has 1 statement then you’re not required to use the curly brackets.
if (true) System.debug(1); else System.debug(2);
















