As per the documentation, trigger.isExecuting returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call.
I am a bit confused by this. If VF page calls a controller function which makes an DML operation firing the trigger, what would be the value of isExecuting in that case?
Best Answer
In brief
Trigger.isExecuting
determines if the context is trigger or Visualforce. If it returns true context is trigger otherwise context is Visualforce or other. In your caseTrigger.isExecuting
will returntrue
.Simple ex:
Create a class:
Now Create a trigger on Contact
Now if any of Contact's record is updated or inserted by Visualforce Controller or manually it will fire a trigger and in the trigger instance method of
TriggerContextDemo
is called and result in System.debugs:If we call the same class from Developer console's execute Anonymous like this:
In this case same class will result in system.debugs: