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