Apex Trigger Basic
Apex Trigger is a stored procedure or code that executes before or after specific data manipulation language(DML) events occur,such as before object records are inserted into the database,or after records have been deleted.
When we use Trigger:
1.We basically use triggers to do operations that cannot be done by point and click tools provided in salesforce.
2.Using Trigger We can do things that we can do through Apex, along with executing SOQL and DML or calling custom methods.
3.Triggers can be created for both standard and custom objects.
Types of Apex Triggers:
- Before Trigger
- After Trigger
When to use Before Trigger:
1.Wanted to update the same record before saving into the database and saving the DML.
2.when you have to perform some complicated validation and can not be achieved by validation rule.
When to use After Trigger:
1.When there is a need to read the System generated Fields like CreatedById, Record Id, Created Date, etc.
2.When you wanted to make some callouts on the same records which are being inserted into the salesforce database.
In the salesforce automation, Trigger is one of the most important tools which help us to automate the business processes.If you want to explore more about Trigger then explore this link-Trigger.