System.TriggerOperation Enum
This enum has the following values, which correspond to trigger events.
Recently i created a post on Swtich Statement. Let see how we can use Swtich Statement and Enum in Trigger:-
Thanks,
Amit Chaudhary
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 );
}
}
}
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
Thank You Amit Sir
ReplyDeleteIt's helpful
ReplyDelete