Salesforce Apex Trigger Events

By in
869
Salesforce Apex Trigger Events

In Salesforce, Apex trigger events are the events that occur before and after any DML operation. DML operations are Insert, Update, Delete, Undelete. Events are in either a BEFORE or AFTER category.

 

Before Events

A Before trigger event is when the record has been created but not committed to the Database. It’s a measure to change data in your triggered records at the first stage of the execution. Before events are as follows.

  1. BEFORE INSERT
  2. BEFORE UPDATE
  3. BEFORE DELETE

 

The purpose of Before events is to make changes to the Trigger.new record and validate a record’s data.

 

After Events

An After trigger event is when the record’s been created and Salesforce has stamped values of Standard Fields like Id, LastModifiedDate, etc. After Events are as follows.

  1. AFTER INSERT
  2. AFTER UPDATE
  3. AFTER DELETE
  4. AFTER UNDELETE

 

Note that Salesforce only provides After Undelete and not before Undelete. That’s because the record isn’t present in the Before Event.

The purpose of After Event is to make changes to a different Object and use a field like Id of the record to perform some complex operations.

 

Conclusion

While developing Apex Trigger Events in Salesforce it’s important to select the appropriate event based on your requirements. If you select an inappropriate event, it may degrade the system performance in the long run.

 

To learn more about Apex and Salesforce, check out some of my related blogs below!

 

Additional Resources

Cover Photo by Nicolas Hoizey on Unsplash

Leave a reply

Your email address will not be published. Required fields are marked *