1

Error:

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

I am trying to write a scheduler class which runs every 60 days. I am getting the error above when I try saving it. Not sure what the problem is.

Here is the code:

 global class BatchEmails_Scheduler implements Schedulable {
         public static String sc = '0 0 18 1/60 * ? *'; 

        global static String schedule() {
                BatchEmails be = new BatchEmails(); 
                return system.schedule('Send Emails', sc, be); 
            }

            global void execute(SchedulableContext sc) {
                BatchEmails be1 = new BatchEmails(); 
                ID batchprocessid = database.executeBatch(be1, 100);
            }

    }
2
  • return system.schedule('<batch_name>', '<cron_string>', new BatchEmails_Scheduler());
    – user46620
    Commented Sep 12, 2017 at 15:42
  • I tried this, but I do not see the job in scheduled jobs after saving it. DO I need to invoke in any other way?
    – user46620
    Commented Sep 12, 2017 at 15:43

1 Answer 1

3

You are trying to pass a Batchable implementation where Schedulable is expected. This is just one reason why it is better to roll both into the same class. Regardless, your schedule method should pass in an instance of BatchEmails_Scheduler:

return system.schedule('<batch_name>', '<cron_string>', new BatchEmails_Scheduler());

Typically, rolling them together reduces the number of classes you have to maintain and adds little overhead:

public with sharing class MyBatch implements Database.Batchable<SObject>, Schedulable
{
    public void execute(SchedulableContext context)
    {
        Database.executeBatch(this);
    }
    public Database.QueryLocator start(Database.BatchableContext context)
    {
        // batch implementation
    }
    public void execute(Database.BatchableContext context, List<SObject> records)
    {
        // batch implementation
    }
    public void finish(Database.BatchableContext context)
    {
        // batch implementation
    }
}
2
  • @sfdcfox Notice the OP is trying to write a static scheduling method, where this would be undefined.
    – Adrian Larson
    Commented Sep 12, 2017 at 15:33
  • N.B. curiously, while you can mix Database.Batchable and Schedulable in the same class implements, you can't mix Schedulable and Queueable on the same class.
    – cropredy
    Commented Sep 12, 2017 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .