function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Edwin KEdwin K 

Check if Trigger is called from Apex Class

Hi All,

 

I want to ask is it possible to check in trigger if the trigger is called from other apex class? The apex class is not future method.. I want to avoid trigger call if called from apex class only..

Any suggestions would be great..

Thanks...

Starz26Starz26

set up a static variable and set it in the class. check it in the trigger.

craigmhcraigmh

If it doesn't really matter which Class it's coming from, as long as it's a class and not an API call, you can use the isExecuting context variable.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

Starz26Starz26

if the class inserts a record and causes the trigger to fire, would isExecuting be = true?

craigmhcraigmh

I set up a trigger to simply write to the debug log the value for trigger.isExecuting.  I then created a page/class where the action method created a new account, and opened the page while running an active debug log. After viewing the log, the value of trigger.isExecuting was true.

Starz26Starz26

craigmh wrote:

I set up a trigger to simply write to the debug log the value for trigger.isExecuting.  I then created a page/class where the action method created a new account, and opened the page while running an active debug log. After viewing the log, the value of trigger.isExecuting was true.


I thought as much...So this would not help the OP as is appears the OP wanted to know if the trigger was called fired as a result of something a class was doing....

 

While it is good info, I am curious to know when the iExecuting() would be used....I fail to see a reason to check if I am running while I am running......

craigmhcraigmh

Yeah, that's why I had to run the test to know the outcome. I've never used it before, or even thought of a use.