What Is Trigger Context Variables?
Context Variables allow developers to access the run-time context of any trigger.
These context variables are contained in system.trigger class.
Considerations Of Context Variables
Points to consider with Trigger Context Variables:
- Trigger.new and Trigger.old cannot be used in Apex DML Operations.
- You can use an sObject to change its own field values using a trigger.new but only in before triggers.
- Trigger.old is always read-only.
- You can not delete Trigger.new.
- Upsert and merge events do not have their own triggers, instead, they fire other triggers based on the events as a result of the merge operation.
Types of Trigger Context Variables
- Trigger.new: This variable returns a list of the new version of sObject records.
- Trigger.old: This variable returns a list of the old version of sObject records.
- Trigger.newMap: This variable returns a map of ids to the new versions of sObject records.
- Trigger.oldMap: A map of IDs to the old version of the sObject records.