Activity Forums Salesforce® Discussions How to call a schedulable apex from batch class in Salesforce?

  • Avnish Yadav

    Member
    August 21, 2018 at 7:36 am

    Hi Anurag,

    You can implement both Database.Batchable and Schedulable in the same class like this:

    global class ScheduleAndBatch implements Database.Batchable<sObject>, Schedulable {

    global Database.QueryLocator start(Database.BatchableContext BC) {

    }
    global void execute(Database.BatchableContext BC, List<sObject> lstSobects) {

    }
    global void finish(Database.BatchableContext BC) {

    }
    global void execute(SchedulableContext sc) {
    Type t = Type.forName('ScheduleAndBatch');
    Database.Batchable< sObject > batchClass = ((Database.Batchable< sObject >) t.newInstance());
    Database.executeBatch(batchClass, this.scope);
    }
    }

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos