Experience Salesforce
Trigger.new in Salesforce| Context Variables in Apex Triggers
What You’ll Learn
- Trigger.new
Topics
- Basics of Triggers
- When to use triggers
- Types of Apex Triggers in Salesforce
- Trigger Order of Execution
- Trigger Context Variables in Salesforce
- Trigger.new in Salesforce| Context Variables in Apex Triggers
- Trigger.old in Salesforce | Context Variables in Apex Triggers
- Trigger.newMap in Salesforce| Context Variables in Apex Triggers
- Trigger.oldMap in Salesforce| Context Variables in Apex Triggers
- Trigger Exceptions
- Best Practice in Triggers
- Trigger Helper Class Pattern
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;
}
}
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.