0

I am trying to run my Batch Class called UltimateParentAccount for every 6am and 12pm using a Cron Job Schedulable name ScheduleUltimeParentAccountBatch.

I tested my batch class and it works well, and then I create a schedulable class which is ScheduleUltimeParentAccountBatch and called the batch class to set a Cron Job.

But I encoutered an Error:

Method does not exist or incorrect signature: void schedule(String, String, UltimateParentAccount) from the type System

Here is my code for my schedulable class:

global class ScheduleUltimeParentAccountBatch implements Schedulable{
    global void execute(SchedulableContext sc){
        UltimateParentAccount upc = new UltimateParentAccount();
        String sch = '0 0 6,12 ? * *';
        System.schedule('My Job', sch, upc);
    }
}

Where did I go wrong? And I checked the some docx about the syntax of schedule method and it seems fine to me but then still I encoutered an error.

1

Scheduler is a class that executes on your specified time. What you are trying to do is Schedule a Batch, Which is not possible directly,

UltimateParentAccount is a batch.

The way we execute batch is

Database.executeBatch(batchable Object)

So your Scheduler code will be:

global class ScheduleUltimeParentAccountBatch implements Schedulable{
    global void execute(SchedulableContext sc){
        UltimateParentAccount upc = new UltimateParentAccount();
        Database.exceuteBatch(upc );

    }
}

Now, to schedule the scheduler at a given time, in execute anon you will use.

String sch = '0 0 6,12 ? * *';
System.schedule('My Job', sch, new ScheduleUltimeParentAccountBatch());

Src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_async_overview.htm

  • I see,I guess there is no way to set a schedule to run a batch class, maybe I should set the cron job in the UI to make it run every day without using the execute anon. – Leorah Sumarong Feb 4 at 18:29
  • 1
    You can make a single class implement Database.batchable and Schedulable, to make a schedulable batch – Pranay Jaiswal Feb 4 at 18:36
  • Do you have any sample or how to set a schedule in batch class? – Leorah Sumarong Feb 4 at 18:45
  • I have run the batch class using your code stated above, how to abort this from execute anon? – Leorah Sumarong Feb 4 at 19:00

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.