Salesforce Spring ’19 Release Notes for Apex Trigger.operationType

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.

Now after Trigger.operationType context variable. we just need to write only one check and its more user friendly.

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.

One thought on “Salesforce Spring ’19 Release Notes for Apex Trigger.operationType

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.