+ Start a Discussion
SF Buzz VutukuriSF Buzz Vutukuri 

How to Stop the trigger for API calls

Hi,

Can any one help us to stop the trigger twice..

Below code not working,we were calling future callouts from trigger only updation made SF end only not API.

can any one guide me how to stop trigger when updation made fromAPI end.

//+++++++++++++My trigger+++++++++++++++++++

trigger LeadstopApICalls on Lead (after update) {

    List<Id>leadids=new List<Id>();

    if(Trigger.isAfter && Trigger.isUpdate )
    {
    
      if (stoprecursive.stopapifire==false)
      {
       Boolean b=false;
       String methodtype='Update';
        for(Lead ld :Trigger.new)
        {
           if(ld.APIUpdate__c=='API')
           {
            b=true;
           }
           leadids.add(ld.id);    
        }
        
        if(!b){
           //call  API class  
            Apicallcontroller.updateLead(leadids,methodtype);
        }
       if(b==true){

          List<Lead>updatefield=[select APIUpdate__c from Lead where Id In :leadids]; 
          
          for(Lead lh:updatefield){
          lh.APIUpdate__c='';
          
          }
          
          //stop the trigger fire again by using static class

          stoprecursive.stopapifire=true; 
          
          update updatefield;
          
        }
     
     
        
    }
        
    }
}

//Static class 
Public class stoprecursive
{

  public static boolean stopapifire=false;

}





 
GautamKumarDrefGautamKumarDref
You need to add before update to the list of paramters, to check befor update made by the api calls.