Trigger Context Variable
In Salesforce Apex triggers, system-provided variables (like Trigger.new, Trigger.old, Trigger.isInsert, Trigger.isBefore) that provide context about the records being processed and the type of DML…
Definition
In Salesforce Apex triggers, system-provided variables (like Trigger.new, Trigger.old, Trigger.isInsert, Trigger.isBefore) that provide context about the records being processed and the type of DML operation that fired the trigger.
In plain English
“Trigger Context Variables in Salesforce Apex triggers are system-provided variables like Trigger.new, Trigger.old, Trigger.isInsert, and Trigger.isBefore. They tell your trigger code about the records being processed and the type of operation happening.”
Worked example
Quadrant Software's developer writes an Apex trigger on the Account object. The trigger uses Trigger Context Variables to know what's happening: Trigger.isBefore and Trigger.isInsert confirm it's running in the before-insert phase; Trigger.new gives him the records about to be inserted; Trigger.old would give the prior values during an update; Trigger.size tells him how many records he's processing for governor-limit awareness. He uses Trigger.new to populate a default value on the Account.PrimaryRegion__c field if the user didn't provide one - a one-line fix that requires zero hardcoded record references. Trigger Context Variables are the contract between the platform and the trigger.
Why Trigger Context Variable matters
In Salesforce Apex triggers, Trigger Context Variables are system-provided variables (like Trigger.new, Trigger.old, Trigger.isInsert, Trigger.isBefore) that provide context about the records being processed and the type of DML operation. They're how trigger code knows what's happening and what records to work with.
Mastering trigger context variables is foundational to Apex trigger development. Trigger.new contains the records being inserted or updated (new values), Trigger.old contains the records before update or being deleted (old values), and boolean variables like Trigger.isInsert identify the operation type. Mature trigger patterns use these variables to implement conditional logic based on operation type and record state.
How organizations use Trigger Context Variable
Trains developers on trigger context variables as foundational trigger knowledge.
Uses context variables for operation-specific logic in their trigger framework.
Implements conditional trigger behavior based on context variable states.
Trust & references
Straight from the source - Salesforce's reference material on Trigger Context Variable.
- Trigger Context VariablesSalesforce Developers
🧠 Test your knowledge
Q1. What are Trigger Context Variables?
Q2. What does Trigger.new contain?
Q3. What does Trigger.isInsert tell you?

Discussion
Loading discussion…