An Apex script that executes before or after the occurrence of any specific DML (data manipulation language) events is called a Trigger. e.g. Any script that occurs before adding or deleting the records from the Database. These Triggers are used to enable the custom actions before or after any changes in the Salesforce Records.
A trigger can be executes before or after the following operations; like insert, update, delete.
There are two types of Triggers in Salesforce
- Before Triggers – This Trigger is used to validate or Update the record values before that saved to the database.
- After Triggers – This Trigger is used to access the value of existing saved record values and use that value to make the changes in other saved records.
All the triggers are bulky in nature by default, and can access the multiple records at a time. Bulk triggers can manage single record updates and bulk operations both like:
- Data import
- com Bulk API calls
- Mass actions, such as record owner changes and deletes
- Recursive Apex methods and triggers that invoke bulk DML statements
A trigger is called as an Apex code that executes before or after the subsequent types of operations: