Search Here

What is the purpose of the Trigger.isExecuting context variable?

 The Trigger.isExecuting context variable in Salesforce is a Boolean value that indicates whether the code is currently executing within the context of a trigger. In my experience, this variable is particularly useful when you have shared utility classes or methods that might be called both from within a trigger and from other parts of the system, such as Visualforce pages or batch Apex.


public class MyUtilityClass {

    public static void performAction() {

        if (Trigger.isExecuting) {

            // Logic specific to trigger execution

            System.debug('Executed within a trigger');

        } else {

            // Logic for non-trigger execution

            System.debug('Executed outside of a trigger');

        }

    }

}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.