Activity Forums Salesforce® Discussions How to schedule batch class based on country in Salesforce?

  • How to schedule batch class based on country in Salesforce?

    Posted by Prachi on December 9, 2019 at 6:22 pm

    I have requirment i need to run my batch class in different time regions based on country

    global class UpdateAccountCallList  implements Database.Batchable<sObject>{
    public String[] country = new String[] {'USA','Canada','Austrila','Japan'}; // these are the countires which i need to run my batch class , can anyone tell me me how to do that please.

    Deepak replied 5 years ago 3 Members · 2 Replies
  • 2 Replies
  • Yogesh

    Member
    December 10, 2019 at 7:18 am

    Hello,

    global class Scheduler_class implements Schedulable{

    public static String sched = '0 00 00 * * ?'; //Every Day at Midnight

    global static String scheduleMe() {
    Scheduler_class SC = new Scheduler_class();
    return System.schedule('My batch Job', sched, SC);
    }

    global void execute(SchedulableContext sc) {

    batchAUpdate_based_on_stage b1 = new batchAUpdate_based_on_stage();
    ID batchprocessid = Database.executeBatch(b1,50);
    }
    }

  • Deepak

    Member
    December 10, 2019 at 2:08 pm

    ust saving the class does not schedule it. You still need to tell the DB to schedule it. I generally write a schedule function within my class so that I can easily call it in one line, that uses my static chron string within the class. Something like this should work

    global class Scheduler_class implements Schedulable{

    public static String sched = '0 00 00 * * ?'; //Every Day at Midnight

    global static String scheduleMe() {
    Scheduler_class SC = new Scheduler_class();
    return System.schedule('My batch Job', sched, SC);
    }

    global void execute(SchedulableContext sc) {

    batchAUpdate_based_on_stage b1 = new batchAUpdate_based_on_stage();
    ID batchprocessid = Database.executeBatch(b1,50);
    }
    }
    The you just need to run Scheduler_class.scheduleMe(); from execute anonymous and it will be scheduled to run at your interval. This is important as this tells the DB to actually schedule it.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos