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
Ritesh__Ritesh__ 

Database.executeBatch cannot be called from a batch or future method.

i am calling a batch class from finish method of another batch class and facing the above error

my finish method code is public class BatchPublicCampaignsToGoogle implements Database.Batchable, Database.Stateful, Database.AllowsCallouts {

public void finish(Database.BatchableContext BC){

        if(newBatch == true)
        {           CalendarSettings__c c= [Select Id, Name, CalendarId__c,CalendarQuery__c,FieldToDisplay__c from CalendarSettings__c WHERE Name = 'Internal marketing Calendar' LIMIT 1] ;
       BatchPublicCampaign bjob = new BatchPublicCampaign();
                Database.executeBatch(bjob);

        }
    }

} but i was facing error Database.executeBatch cannot be called from a batch or future method.

after finishing Batch request i am trying to call it(i have to call it for two times) again.so i call it.

How to get rid of error.i know we can call a batch class from finish method of a Batch Class but why i am getting this error ??

 

Best Answer chosen by Admin (Salesforce Developers) 
SRKSRK
it work only in 27 version

All Answers

SRKSRK

what is the version of you apex batch job apex class ???

 

SRKSRK
it work only in 27 version
This was selected as the best answer