Activity Forums Salesforce® Discussions What is isExecuting in Salesforce?

  • Deepak

    Member
    January 27, 2020 at 12:18 pm

    Hi Shubham,

    Trigger. isExecuting in Salesforce determines if the context is trigger or Visualforce.

    If it returns true

    then it is trigger,

    Otherwise it is VisualForce.

    For e.g.

    public class TriggerContextCheckingisExecuting
    {
      public Boolean updateContact(Contact[] conList)
      {
         // Will not update contact if method is called in TriggerContext
         if(Trigger.isExecuting)
         {
            // Do Not Update Any contact
            System.debug(‘ $ $ NOT updating contacts’);
         }
         else
         {
           // update contacts
           System.debug(‘ $  updating contacts’);
         }
         System.debug(‘ $ return ‘ + Trigger.isExecuting);
         return Trigger.isExecuting;
      }
    }
    Apex Trigger on Contact object
    
    trigger ContextCheckTrigger on Contact (before insert, before update)
    {
       TriggerContextisExecuting isExecuting = new isExecuting();
       isExecuting.updateContact(Trigger.New);
    }

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos