Types of Apex Triggers in Salesforce

There are two types of Triggers in Salesforce:

     

      1. Before Triggers: These triggers are used to update or validate triggering record values before they’re saved to the database.

      1. After Triggers: These are used to access fields values that are already set by the system like recordId, lastModifiedDate field for performing after save actions like sending mail. After Triggers are also used to make changes to other records. However, they cannot be used on the record which initiated/triggered the execution of after trigger because the records that fire the after trigger are read-only.

        Example:-

        
            
    trigger FirstTrigger on Account(before insert) {
        System.debug(‘I am before insert.’);
    }
    Trigger SecondTrigger on Account(after insert) {
        System.debug(‘I am after insert.’);
    }