Activity Forums Salesforce® Discussions What is recursive batch in Salesforce? How to do a recursive batch?

  • Yogesh

    Member
    November 12, 2019 at 3:29 pm

    Hello,

    You can call batch from the previous batch finish() method. For example:-

    public class RecursiveBatch implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
    private final Date passedDate;

    public RecursiveBatch(Date passedDate) {
    this.passedDate = passedDate;
    }

    public Database.QueryLocator start(Database.BatchableContext BC) {
    return Database.getQueryLocator( < QUERY >);
    }

    public void execute(Database.BatchableContext BC, List<sObject> scope) {

    }

    public void finish(Database.BatchableContext BC) {
    if(Date.today() <= this.passedDate) {
    Database.executeBatch(new RecursiveBatch(passedDate.addDays(1)));
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos