I currently have a batch which calls itself if it finds records still falling into scope. I am using a static boolean variable to do this. Now i have found out our email system cannot handle thousands of emails within seconds, so they have advised me to send 50 emails a minute instead. I can swap the batch size to 50 easily however i am not sure how i can have the batch wait 1 minute before calling itself, if it still has records to process.

Any ideas are welcome.

Thank you!


There's a specific method for this, System.scheduleBatch, which can be called from the finish method to chain indefinitely:

global void finish(Database.BatchableContext context) {
    System.scheduleBatch(new BatchClassName(), 'NextJobInChain', 1);

Where the second parameter should be a unique job name, and the third parameter is the number of minutes to wait.

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.