Trigger.isExecuting
is to determine that your current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call.
Here is an example of Apex Class, this class can identify current context for the Apex code is a trigger using Trigger.isExecuting
.
Apex Class:
public class AccountHandler { public Boolean handleAccount(List<Account> accList){ System.debug('Trigger is executing : ' + Trigger.isExecuting); if(Trigger.isExecuting){ //Do what ever you want to do as part of the trigger invocation } else{ //Do what ever you want to do if the call originated from different context, such as from controller. } return Trigger.isExecuting; } }
Apex Trigger:
trigger AccountTrigger on Account (before insert, before update){ AccountHandler handler = new AccountHandler(); handler.handleAccount(Trigger.New); }