Experience Salesforce

Trigger.new in Salesforce| Context Variables in Apex Triggers

What You’ll Learn

  • Trigger.new

Trigger.new in Salesforce returns a list of the new version of sObject records, and is available in insert, update, and undelete triggers.

Trigger.new in Salesforce Example:

trigger AccountTrigger on Account (before insert) {
    for (Account acc: Trigger.new) {
        acc.NumberOfEmployees = 100;
    }
}

In this example, Trigger.new allows us to modify the NumberOfEmployees field before the record is inserted into the database.

trigger ApexTrigger on Account(before insert) {
    for (Account acc: Trigger.new) {
        acc.NumberOfEmployees = 100;
    }
}
LWC Training
Next Topic

Need Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
-9++
Rakshabandhan Sale