0

Getting the following error while updating a record via an external app. The trigger is calling a batch when this record is getting updated.

Update failed. First exception on row 0 with id 0013H000008gq59QAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ivybat.AccountOperation: execution of AfterUpdate

caused by: System.AsyncException: Database.executeBatch cannot be called from a batch start, batch execute, or future method.

Trigger.ivybat.AccountOperation: line 121, column 1: []

Also getting the following error description recorded in one of the custom objects primarily created to log the errors while updating/inserting from the external app.

Update failed. First exception on row 0 with id 0013H000008gq59QAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ivybat.AccountOperation: execution of AfterUpdate

caused by: System.AsyncException: Database.executeBatch cannot be called from a batch start, batch execute, or future method.

Trigger.ivybat.AccountOperation: line 121, column 1: []

Debugging the class mentioned in the error description, found the recursion is happening. So I had tried to stop the recursion but still facing the same issue.

I am not going through the solution suggested in the following blog for System.AsyncException: Database.executeBatch cannot be called from a batch start, batch execute, or future method. as this is not throwing any issue in other orgs which are using the same managed package.

attaching the following block of code from the Trigger

if(trigger.isUpdate && trigger.isafter)
        {
            Map<String, Boolean> triggerLogicMap = TriggerLogicService.getDuplicationCheck(new Set<String>{'SKIP_AccountUpdate_Operation'});
            if(triggerLogicMap.get('SKIP_AccountUpdate_Operation') == Null 
               || triggerLogicMap.get('SKIP_AccountUpdate_Operation') == false) {
                   AccountOperationTriggerHelper.updateSalesOrgKey(trigger.new);        //    method calling to set SalesOrg key and tax classification key
                   Set<Id> accId = new Set<Id>();
                   Set<String> endMkts = new Set<String>();
                   map<Id,String> accmap = new map<id,String>();
                   boolean isReactivated = false;
                   for(Account acc : trigger.new){
                       system.debug(acc.ivybase__Status__c);
                       system.debug(trigger.oldMap.get(acc.Id).ivybase__Status__c);
                       if(acc.ivybase__Status__c != null && acc.ivybase__Status__c.equals('Active') && (acc.ivybase__Status__c != trigger.oldMap.get(acc.Id).ivybase__Status__c)){
                           isReactivated = true;
                           accmap.put(acc.Id,acc.market_iso__c);
                           accid.add(acc.id);
                       }
                   }
                   
                   if(isReactivated && (accId.size() > 0)){
                       if(!RoutePlanDetailsService.firstRun){
                           RoutePlanDetailsService.firstRun = true;
                           System.debug('Run the batch clas');
                           batchCalVisitRecords br = new batchCalVisitRecords(accId);
                           database.executeBatch(br);
                       }
                       
                   }
                   if(isReactivated && (accmap != null)){
                       CampaignTriggerHelper.insertvfonACCReactivation(accmap);
                   }
               }
        } 

What would be suggested in such a scenario? Thanks in advance.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    You appear to have used the term `batch`, and used the tag [[tag:batch-file]], however, I cannot see any batch file code in your question, or any reference to a file with a `.bat` or `.cmd` extension, which would indicate the use of one. Could you please clarify your questions' relationship to that used tag? _(Please feel free to hover over, or click on, the batch-file tag, to get a description of its use throughout this site.)_ – Compo Apr 01 '21 at 14:46

0 Answers0