About

all about SFDC

Sunday 2 June 2019

Using trigger events / context variables with enum System.TriggerOperation

04:44

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




0 comments

Note: only a member of this blog may post a comment.

Powered by Blogger.

Contact form

Name

Email *

Message *

Visualforce

Apex

Lightening UI

Translate

Comments