Are you still writing two checks for detecting trigger events like before insert, before update, after update etc. For example Trigger.isInsert && Trigger.isBefore for before insert ? Now Salesforce made this easy to obtain the DML Operation Information.
Get more information here
Obtain DML Operation Information Using Trigger.operationType Context Variable
So basically this new context variable will make our code more readable and contains all information about DML Operations.
Earlier if we need to write trigger on the before insert event, then we need to use two context variables as below.
1 2 3 |
if(Trigger.isBefore && Trigger.isInsert){ // Before Insert logic go here } |
Now after Trigger.operationType context variable. we just need to write only one check and its more user friendly.
1 2 3 |
if(Trigger.operationType == TriggerOperation.BEFORE_INSERT){ // Before Insert logic go here } |
Similarly we can use for other trigger events.
Trigger.operationType returns the System.TriggerOperation enum, and System.TriggerOperation enum has following values : BEFORE_INSERT, BEFORE_UPDATE, BEFORE_DELETE,AFTER_INSERT, AFTER_UPDATE, AFTER_DELETE, and AFTER_UNDELETE.
Hope you will start using this new update in your next trigger task.