+ Start a Discussion
Matt Scholl 10Matt Scholl 10 

System.scheduleBatch not being interpreted properly?

I am trying to reuse a piece of code I've used many times before. The code schedules a batch class from another Apex class. When I try to edit it in Developer Console or an IDE, I get the following error: "Method does not exist or incorrect signature: void scheduleBatch(testBatch, String, Decimal) from the type System". testBatch IS a batchable class. Why is the compiler pulling the NAME of the batchable class into the method?

Here is my code:
Apex class:
public class testClass {
    public static void testSchedule() {
        testBatch batchable = new testBatch();
        String jobName = 'testBatch';
        Decimal minutesFromNow = 0.0;

        try {
            String cronId = System.scheduleBatch(batchable, jobName, minutesFromNow);
            CronTrigger ct = [SELECT Id, NextFireTime FROM CronTrigger WHERE Id = :cronID];
            System.debug(jobName + ' jobId: ' + cronID);
            System.debug(jobName + ' next fire time: ' + ct.NextFireTime);
        } catch (Exception e) {
            System.debug('Error scheduling batch: '+e.getMessage());
        }
    }
}

Here is the batch class:
global class testBatch implements Database.Batchable<sObject> {
    private static String query;

    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }

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

    global void finish(Database.BatchableContext BC){
    }
}
Thanks in advance!
Best Answer chosen by Matt Scholl 10
Krishna.AvvaKrishna.Avva
Hi matt,

Can you try changing the minutesFromNow to Integer and make it greater than 0. This is what Salesforce documentation says

minutesFromNow
Type: Integer
The time interval in minutes after which the job should start executing. This argument must be greater than zero.


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

Regards,
Krishna Avva