function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
moverdorfmoverdorf 

Schedule APex Class... Compile error

I am trying to create a scheduled Apex batch job, I created the class below:

 

global class BatchLoadDaily3 implements Schedulable{
    
    global void execute(SchedulableContext sc) {
        //  Instantiate batch class
    BatchLoadDaily3 bat = new BatchLoadDaily3('','CASCADE');
    Database.executeBatch(bat, 20);
    }
}

 

But I am getting an error when I try to save the code:

Error: Compile Error: Constructor not defined: [BatchLoadDaily3].<Constructor>(String, String) at line 5 column 27

 

Can anyone help me out with the Constructor for this?

 

Thanks so much in advance!

 

 

 

RockzRockz

Hi..

 

Try below Code...

 

global class BatchLoadDaily3 implements implements Schedulable{

String query;
global BatchLoadDaily3(){
// Batch Constructor
}
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}

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

    BatchLoadDaily3 bat = new BatchLoadDaily3('','CASCADE');
    Database.executeBatch(bat, 20);

}

global void finish(Database.BatchableContext BC){
// Logic to be Executed at finish
}

}

 

 

Please accept my answer as a solution if my solution was helpful. This will make it available to others as a proper answer. If you felt that I went above and beyond please give me Kudos by clicking on on the star icon.

 

 

Thanks,

Cool Sfdc

 

 

 

 

 

Avidev9Avidev9

well for sure you are doing something wrong with the code. It seems like you self referencing the class name from inside the class

 

global class BatchLoadDaily3 implements Schedulable{
    
    global void execute(SchedulableContext sc) {
        //  Instantiate batch class
    BatchLoadDaily3 bat = new BatchLoadDaily3('','CASCADE');
    Database.executeBatch(bat, 20);
// this should be a batch class and should have constrcutor to accept strings. Here in your code you seem to refrence the schedulable class instead of the batch class
} }