title: Trigger running twice where update call is made in Insert Event(If Static Variable = False is used)
body: <p>I have a trigger handler where an <strong>Update</strong> call is made in the AfterInsert event.</p>
  <p>But I want to stop the <strong>AfterUpdate</strong>,<strong>BeforeUpdate</strong> Methods which are getting invoked in <strong>AfterInsert</strong> Call.</p>
  <p>If I use <strong>Static</strong> Variable To <strong>False</strong> in the <strong>AfterInsert</strong> Event then Two times the <strong>BeforeUpdate</strong> and <strong>AfterUpdate</strong> Event is Called.</p>
  <p>But if I didn't used <strong>Static</strong> Variable then only One time a <strong>BeforeUpdate</strong> and <strong>AfterUpdate</strong> Method is Getting Called.</p>
  <p>But what I need is If i use <strong>Static</strong> Variable = <strong>False</strong> in the <strong>AfterInsert</strong> Event then the <strong>BeforeUpdate</strong> and <strong>AfterUpdate</strong> Shouldn't get called even for Once..
  Can anyone guide me on this, please</p>
  <p><strong>Trigger</strong></p>
  <p>trigger CaseTrigger on Case (before insert, before update, before delete,
  after insert, after update, after delete,  after undelete)
  {
  CaseTriggerHandler handler = new CaseTriggerHandler();</p>
  <pre><code>switch on trigger.operationType{
      when BEFORE_INSERT{
          System.debug('BEFORE_INSERT');
           handler.onBeforeInsert (Trigger.new);
      }
      when BEFORE_UPDATE{
          handler.onBeforeUpdate(Trigger.oldMap, Trigger.new);
      }
      when BEFORE_DELETE{
          handler.onBeforeDelete(Trigger.oldMap);
      }
      when AFTER_INSERT{
          System.debug('AFTER_INSERT');
          handler.onAfterInsert(Trigger.new,Trigger.oldMap);
      }
      when AFTER_UPDATE{
          
          handler.OnAfterUpdate(Trigger.new,Trigger.oldMap);
         
      }
      when AFTER_DELETE{}
      when AFTER_UNDELETE{}
  }
  </code></pre>
  <p>}</p>
  <p><strong>Trigger handler</strong></p>
  <p>public with sharing class CaseTriggerHandler
  {
  CaseHelper helper = new CaseHelper();</p>
  <pre><code>public CaseTriggerHandler(){}
  
  public void onAfterInsert(List&lt;Case&gt; insertedCases,Map&lt;Id,Case&gt; oldMapCase)
  {
      system.debug('44');
      List&lt;Case&gt; casesForUpdate = insertedCases.deepClone(true, true, true);
      
      helper.EnsureAccountIsIdentified(casesForUpdate); 
      system.debug('55');
      
      helper.AttachEntitlements(casesForUpdate);
      system.debug('66');
      CaseHelper.DontFireTrigger = False;
      **update casesForUpdate;**
      system.debug('77');
  }
  
  public void onBeforeUpdate(Map&lt;Id,Case&gt; oldCases, List&lt;Case&gt; newCases)
  {    
      system.debug('88');
      helper.HandleClosedCaseCommunication(oldCases, newCases);
      system.debug('99');
      helper.UpdateSubjectFieldBeforeUpdate(oldCases,newCases);
      helper.UpdateStatusFieldBeforeUpdate(oldCases,newCases);
      system.debug('100');
  }
  public void onBeforeInsert(List&lt;Case&gt; newCases)
  {
     
      system.debug('11');
      helper.UpdateSubjectFieldBeforeInsert(newCases);
      system.debug('22');
      helper.updateAccountIdInCase(newCases);
      system.debug('33');
  }
  
  public void OnAfterUpdate(List&lt;Case&gt; newCases,Map&lt;Id,Case&gt; oldMapCase)
  {
      system.debug('111');
      helper.createCaseStatusChangeRecord(newCases,oldMapCase);
      system.debug('222');
  }
  </code></pre>