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
Abhishek Singh 88Abhishek Singh 88 

Is there any to stop recursive trigger rather than static variable.

Hi All, 
Trigger recursion is still persisting , i have used static variable though. here is code snippet.
public void decommising(List<BMCServiceDesk__BMC_BaseElement__c> newbelist,map<id,BMCServiceDesk__BMC_BaseElement__c> oldbelist)
    {    
       
           for(BMCServiceDesk__BMC_BaseElement__c be:newbelist)
        {
            beid.add(be.id);
        }
if(CheckRecursive.cmdbserver1==false)
{
           serverdecommission(newbelist,oldbelist);
    }
}
public void serverdecommission(List<BMCServiceDesk__BMC_BaseElement__c> newbelist1,map<id,BMCServiceDesk__BMC_BaseElement__c> oldbelist1)
for(BMCServiceDesk__BMC_BaseElement__c berec:childCis)//related base element record could be source or destination
        {
//putting relationship for ci's in map, to get id of cis level 2.
              if(destinationmap1.get(berec.id)!=null)
              destinationList.addAll(destinationmap1.get(berec.id));
               system.debug('destinationList'+destinationList);
               if(sourcemap1.get(berec.id)!=null)
               sourceList.addAll(sourcemap1.get(berec.id));
                system.debug('sourceList'+sourceList);
                if(sourceList.size()>0)
                sourcedestinationlist.addAll(sourceList);
                  if(destinationList.size()>0)
                sourcedestinationlist.addAll(destinationList);
               system.debug('sourcedestinationlist'+sourcedestinationlist);
               for(BMCServiceDesk__BMC_BaseRelationship__c brrec:sourcedestinationlist)
               {
                   if(brrec.BMCServiceDesk__Source_ClassName__c=='BMC_Application')
                       besourceid.add(brrec.BMCServiceDesk__Source__c);
                      if(brrec.BMCServiceDesk__Destination_ClassName__c=='BMC_Application')
                          besourceid.add(brrec.BMCServiceDesk__Destination__c);
                   
               }
               if(besourceid.size()>0)
                   baseapplist=[select id,name,HITRUST__c,PCI__c,PHI__c,Fisma_High_New__c,Fisma_Low_New__c,Fisma_Mod_New__c,SOC__c,SOC2__c,SOX__c,Environment__c,UAR__c,BMCServiceDesk__ClassName__c from BMCServiceDesk__BMC_BaseElement__c where ID IN:besourceid];
                   system.debug('baseapplist'+baseapplist);
                   
                   for(BMCServiceDesk__BMC_BaseElement__c baseapp:baseapplist)
                     {
                              if(baseapp.HITRUST__c)
                                  
                                  flag1=true;
                     }
                     for(BMCServiceDesk__BMC_BaseElement__c basebe:newbelist1)
                     {
                        if(oldbelist1.get(basebe.id).HITRUST__c!=basebe.HITRUST__c && basebe.HITRUST__c==false)
                        {
                            if(flag1)
                            {
                              berec.HITRUST__c=true;  
                            }
                              else{
                                     berec.HITRUST__c=false;
                                }                           
                     }
                     }
        baseelementlist.add(berec); 
        }
basemap.putAll(baseelementlist);
        system.debug('base map'+basemap.values());
           if (basemap.size()>0)
           {
              update basemap.values();
            CheckRecursive.cmdbserver1=true;
 
               system.debug(basemap);
              }   
    }

Any help would be appriciated.
Greg HGreg H
Another option would be to use a static set. Add the Id of the record to the set and check the set for the Id before processing further.
-greg