Friday 1 June 2018

Trigger.OperationType | System.TriggerOperation Enum | Salesforce Summer ’18 Release Notes

System.TriggerOperation Enum
This enum has the following values, which correspond to trigger events.
  • AFTER_DELETE
  • AFTER_INSERT
  • AFTER_UNDELETE
  • AFTER_UPDATE
  • BEFORE_DELETE
  • BEFORE_INSERT
  • BEFORE_UPDATE

Recently i created a post on Swtich Statement. Let see how we can use Swtich Statement and Enum in Trigger:-

trigger AccountTrigger1 on Account ( before Insert ,Before Update , After Insert, After Update) {
       switch on Trigger.OperationType  {
            when BEFORE_INSERT
            {
                System.debug('BEFORE_INSERT------>' + Trigger.OperationType );
                System.debug(Trigger.OperationType +'-Before Insert-->'+Trigger.isInsert+'--->'+Trigger.isBefore);
            }
            when AFTER_INSERT
            {
                System.debug('AFTER_INSERT ------->' +Trigger.OperationType );
                System.debug(Trigger.OperationType +'-After Insert-->'+Trigger.isInsert+'--->'+Trigger.isAfter);
            }
            when BEFORE_UPDATE, AFTER_UPDATE
            {
                System.debug('BEFORE_UPDATE or AFTER_UPDATE----->' +Trigger.OperationType );
            }
        }
}


Thanks,
Amit Chaudhary 

2 comments: