When To Use Triggers In Apex?
1. An Apex Trigger is a Stored Apex procedure that is called whenever a record is inserted, updated, deleted, or undeleted. If any change happens to single or multiple records, the Apex Trigger created on that object will be fired.
For example, we can have a trigger run:
- Before an object’s record is inserted into the database.
- After a record has been deleted.
- Even after a record is restored back from recycle bin.
2. Use triggers to perform tasks that can’t be done using a point & click tool in Salesforce. If the task is possible using point & click tools then always prefer doing it from them.
3. Triggers are active by-default when created and Salesforce automatically fires active triggers when specified database event occurs.