+ Start a Discussion
anvesh@force.comanvesh@force.com 

Both If and else statements executed at a time ?

https://developer.salesforce.com/forums/#!/feedtype=RECENT&criteria=ALLQUESTIONSI am facing a difficult issue...as If and else statements were executed at a time.The difficult is  it was executed correctly in sand box and not 
in production it was executed if and else statements at a time......after if statement it enters in to else statement.


 for(Market_Metrics__c c: cIsBeforeAnnuity)
        {
              System.debug('tlistAnnuity'+tListAnnuity);         
        try
         {
            if(c.Exclude_from_Territory__c == false)
            {
               for(Territory__c t: tListAnnuity)
               {
                if(aIBDMap.get(c.SFDC_Account_Name__c) != null) //experimental code.
                 {
                  System.debug('AccountTest'+aIBDMap.get(c.SFDC_Account_Name__c).Name);                 
                  System.debug('ClsBefore'+cIsBeforeAnnuity);
                  System.debug('AccountChannel'+aIBDMap.get(c.SFDC_Account_Name__c).channel__c);  
                  System.debug('Protected Accounts'+t.Protected_Accounts__c);
                 
                 if(c.State__c== t.state__c && c.Zip_Code__c.substring(0,5) >= t.zip_start__c && c.Zip_Code__c.substring(0,5) <= t.zip_end__c && t.type__c =='Annuity' && aIBDMap.get(c.SFDC_Account_Name__c).Name == t.Protected_Accounts__c)
                          {
                      System.debug('EntryTest1'+t.Protected_Accounts__c);                 

                      c.Annuity_Territory__c = t.Id;  
                                                                                          
                      System.debug('The current ID is Pro ' + t.Id);                  
                  }                             
                 else
                      if
(aIBDMap.get(c.SFDC_Account_Name__c) != null) //experimental code.
                 {                       
                    System.debug('ProtAcc'+t.Protected_Accounts__c);

                    if(c.State__c== t.state__c && c.Zip_Code__c.substring(0,5) >= t.zip_start__c &&
                      c.Zip_Code__c.substring(0,5) <= t.zip_end__c && aIBDMap.get(c.SFDC_Account_Name__c).channel__c == t.channel__c &&t.type__c =='Annuity'&&t.Protected_Accounts__c == null)

                    {
                     System.debug('Entry Test2'+t.Protected_Accounts__c);

                          c.Annuity_Territory__c = t.Id;   
        
                      System.debug('The current ID is >>' + t.Id);
                    }                  
                 }                 
         catch (System.Exception e)
         {
            System.debug(e.getMessage());         
            //c.addError('[Error AC] There was an unexpected error while saving the record, please Contact support for assistance');               
         }
       }

      


 
Shashikant SharmaShashikant Sharma
This looks to be a trigger code. Do you have any workflows this object having the trigger. If you have deactivate them and then test. If it works fine then it would mean that this trigger running recursively. Once it met if and it does not so it goes in else. If that is the case than use static boolean varible to stop recurssion.

Thanks
Shashikant