What are the various events on which a trigger can fire?

2.1K    Asked by CarolynBuckland in Salesforce , Asked on Aug 1, 2020
Answered by Carolyn Buckland

 A trigger is a set of instructions which can be fired based on the below mentioned events. We can include one or more events or all events in one trigger based on our requirement or what we need to achieve through the code. Also, we can include trigger events one or more using comma separated.

Below are the trigger events :-


Trigger Events

Description and Example

before insert

This type of triggers will be fired when newly record is going to save in database and we need to perform some action on that before saving to database. Also, in before insert trigger, New is stored all new record list which is going to insert.

Examples:

This trigger will set subject for case as mentioned in code.

trigger casesubjecttrigger on Case (before insert) {

    for(Case caserecord : Trigger.New) {

        caserecord.Subject = 'Test Case created';

    }

}


before update

Basically before update store the list of records which is going to update before saving to database.

Example :-

If we want to run trigger above mentioned trigger in before update trigger then it is possible. The only difference is that

trigger casesubjecttrigger on Case (before insert,before update) {

    for(Case caserecord : Trigger.New) {

        caserecord.Subject = 'Test Case created';

    }

}



before delete


after insert


after update


after undelete


after delete




Your Answer

Interviews

Parent Categories