In summer'18 release Salesforce has first introduced enum System.TriggerOperation which consists specific set of trigger context variables AFTER_DELETE, AFTER_INSERT, AFTER_UNDELETE, AFTER_UPDATE, BEFORE_DELETE, BEFORE_INSERT,BEFORE_UPDATE.
This enum makes life easy for developer from using different context variables like triger.isAfter and trigger.isInsert with a bunch of AND statements and IF statements. The new Trigger context variable Trigger.operationType will returns an enum System.TriggerOperation during trigger context. With this enum we can easily identify the current trigger context and can invoke our logic from handlers. This enum can also be used with in a trigger handler class.
The simple snippet below demonstrates using this enum with a switch statement.
Result in debug logs when updated a record on Account object.
Happy coding, cheers!!!
Resources:
Releases notes Spring'19
TriggerOperation Enum
This enum makes life easy for developer from using different context variables like triger.isAfter and trigger.isInsert with a bunch of AND statements and IF statements. The new Trigger context variable Trigger.operationType will returns an enum System.TriggerOperation during trigger context. With this enum we can easily identify the current trigger context and can invoke our logic from handlers. This enum can also be used with in a trigger handler class.
The simple snippet below demonstrates using this enum with a switch statement.
Result in debug logs when updated a record on Account object.
Happy coding, cheers!!!
Resources:
Releases notes Spring'19
TriggerOperation Enum
By — anil
04:44