Querying All Records with a SOQL Statement..............................................................................................60
Locking Statements.....................................................................................................................................................60
Locking in a SOQL For Loop........................................................................................................................61
Avoiding Deadlocks.........................................................................................................................................61
Transaction Control.....................................................................................................................................................61
Exception Statements..................................................................................................................................................62
Throw Statements...........................................................................................................................................62
Try-Catch-Finally Statements.........................................................................................................................62
Chapter 3: Invoking Apex..........................................................................................................64
Triggers........................................................................................................................................................................65
Bulk Triggers...................................................................................................................................................66
Trigger Syntax..................................................................................................................................................66
Trigger Context Variables................................................................................................................................67
Context Variable Considerations.....................................................................................................................68
Common Bulk Trigger Idioms.........................................................................................................................69
Defining Triggers.............................................................................................................................................70
Triggers and Merge Statements.......................................................................................................................72
Triggers and Recovered Records......................................................................................................................73
Triggers and Order of Execution.....................................................................................................................73
Operations That Do Not Invoke Triggers.......................................................................................................75
Fields that Cannot Be Updated by Triggers....................................................................................................76
Trigger Exceptions...........................................................................................................................................76
Apex Scheduler............................................................................................................................................................76
Anonymous Blocks......................................................................................................................................................81
Apex in AJAX..............................................................................................................................................................82
Chapter 4: Classes, Objects, and Interfaces.................................................................................84
Understanding Classes.................................................................................................................................................85
Apex Defining Classes.....................................................................................................................................85
Extended Class Example.................................................................................................................................86
Declaring Class Variables.................................................................................................................................89
Defining Class Methods..................................................................................................................................90
Using Constructors..........................................................................................................................................91
Access Modifiers..............................................................................................................................................92
Static and Instance...........................................................................................................................................93
Apex Properties................................................................................................................................................96
Interfaces and Extending Classes................................................................................................................................99
Parameterized Typing and Interfaces.............................................................................................................100
Custom Iterators............................................................................................................................................102
Keywords...................................................................................................................................................................104
Using the final Keyword................................................................................................................................104
Using the instanceof Keyword.......................................................................................................................104
Using the super Keyword...............................................................................................................................104
Using the this Keyword.................................................................................................................................105
Using the transient Keyword.........................................................................................................................106
ii
Table of Contents