1

i write below trigger on that time this error is appear plz help me

trigger GK_betaObject_trg on GIRI2__betaObject__c(after insert,after delete,after update) { 
   List<Rollup_Config__c> sfRollup = [Select Id,Parent_Field_Name__c,Parent_Object_Name__c,
 Parent_Relation_Name__c,Child_Field_Name__c , 
          Child_Object_Name__c ,Operation_Type__c,Filter1__c,Filter2__c,
   Filter3__c,Filter4__c,Filter5__c from Rollup_Config__c where Child_Object_Name__c ='GIRI2__betaObject__c' ]; 
   if(sfRollup.size() > 0){ 
     for(Rollup_Config__c conf: sfRollup){ 
         List<Id> pIds = new List<Id>(); 
         List<sobject> dataList = Trigger.IsDelete ?  Trigger.old :Trigger.new; 
         for(sobject rec :  dataList){ 
            pIds.add(String.valueOf(rec.get(conf.Parent_Relation_Name__c))); 
         } 
         if(pIds!=null && pIds.size() > 0){ 
             System.Debug('pIds : '+pIds); 
             LookUpConfigBatch batchObj = new LookUpConfigBatch(conf); 
             batchObj.pIds = pIds; 
             String batchId = Database.executeBatch(batchObj); 
         } 
     } 
 } 
}
  • what is the API version of your batch class – Himanshu Oct 16 '15 at 14:26
  • 33 version Himanshu... – user25465 Oct 16 '15 at 14:28
  • go to your Apex Class detail page you will see five tabs Class Body, Class Summary, Version Settings, Log Filters click on version settings tab – Himanshu Oct 16 '15 at 14:31
  • 2
    then it seems that your code is running another batch or updating some other records from same object. You have written your batch call which is not a good practice this issue is coming. you should rectify your code and move batch code outside the trigger. – Himanshu Oct 16 '15 at 14:40
2

Some batch or future process is updating records which is causing this to attempt to execute another batch and you cannot do that.

To Stop the error:

if(pIds!=null && pIds.size() > 0 && !system.isFuture() && !system.isBatch()){ 
             System.Debug('pIds : '+pIds); 
             LookUpConfigBatch batchObj = new LookUpConfigBatch(conf); 
             batchObj.pIds = pIds; 
             String batchId = Database.executeBatch(batchObj); 
         } 

Then rerun all your test methods to ensure it did not stop any business logic from happening. If you do not have good test methods you will need to inspect your code / logic to ensure that all updates are happening as expected.

  • First error: Update failed. First exception on row 0 with id a0328000003I20KAAS; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GIRI2.GK_betaObject_trg: execution of AfterUpdate caused by: System.AsyncException: Database.executeBatch cannot be cal – user25465 Oct 16 '15 at 14:57
  • deploy after run the process i get that error above – user25465 Oct 16 '15 at 14:58
  • Then either you did not make the changes I made or it is not coming from that piece of code..... – Eric Oct 16 '15 at 15:01
  • then how to rectify that error.... – user25465 Oct 16 '15 at 15:04
  • 1
    You will have to do some debugging. Without seeing your code for the entire transaction it is hard to say. Simply, you CANNOT fire off another batch during a transaction started from the start or execute method. – Eric Oct 16 '15 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.