Free Salesforce Developers Tutorials >

Chapter - 9 Apex Triggers >

Trigger Context Variables

Trigger Context Variables

What You’ll Learn


S2 Labs

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:

  1. Trigger.new and Trigger.old cannot be used in Apex DML Operations.
  2. You can use an sObject to change its own field values using a trigger.new but only in before triggers.
  3. Trigger.old is always read-only.
  4. You can not delete Trigger.new.
  5. 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

  1. Trigger.new:  This variable returns a list of the new version of sObject records.
  2. Trigger.old: This variable returns a list of the old version of sObject records.
  3. Trigger.newMap: This variable returns a map of ids to the new versions of sObject records.
  4. Trigger.oldMap:  A map of IDs to the old version of the sObject records.
Salesforce certifications

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

Your email address will not be published. Required fields are marked *