Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
DictionaryTTrigger Context Variable
DevelopmentAdvanced

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…

§ 01

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.

§ 02

In plain English

👋 Study buddy

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.

§ 03

Worked example

scenario · real-world use

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.

§ 04

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.

§ 05

How organizations use Trigger Context Variable

CodeBridge

Trains developers on trigger context variables as foundational trigger knowledge.

Quantum Labs

Uses context variables for operation-specific logic in their trigger framework.

TerraForm Tech

Implements conditional trigger behavior based on context variable states.

§

Trust & references

Official documentation

Straight from the source - Salesforce's reference material on Trigger Context Variable.

Was this entry helpful?
Help us write better definitions. Quick reactions or detailed edit suggestions.
§

🧠 Test your knowledge

Q1. What are Trigger Context Variables?

Q2. What does Trigger.new contain?

Q3. What does Trigger.isInsert tell you?

§

Discussion

Loading…

Loading discussion…