Trigger.new in Salesforce| Context Variables in Apex Triggers
Chapter 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 more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.