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
CooldayCoolday 

How to schedule my batch class for every 6 hours ?

How to schedule my batch class for every 6 hours ?
This is my scheduler -
 
global class UpdateBatchSchedule implements Schedulable{
    global void execute(SchedulableContext ctx) {
        UpdateBatch p = new UpdateBatch();
        database.executeBatch(p,200);
    }  
}

 
Best Answer chosen by Coolday
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you try the schedular as below cron job for scheudling it. it runs at 12am, 6AM,12PM,6PM every day


 
global class UpdateBatchSchedule implements Schedulable{
    global void execute(SchedulableContext ctx) {
        UpdateBatch p = new UpdateBatch();
        database.executeBatch(p,200);
    }  
}


You can use the same class which you have written . Just execute this in anonomous window.
 
UpdateBatchSchedule m = new UpdateBatchSchedule();

String sch = '0 0 0,6,12,18 ? * *';
String jobID = system.schedule('Merge Job', sch, m);


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you try the schedular as below cron job for scheudling it. it runs at 12am, 6AM,12PM,6PM every day


 
global class UpdateBatchSchedule implements Schedulable{
    global void execute(SchedulableContext ctx) {
        UpdateBatch p = new UpdateBatch();
        database.executeBatch(p,200);
    }  
}


You can use the same class which you have written . Just execute this in anonomous window.
 
UpdateBatchSchedule m = new UpdateBatchSchedule();

String sch = '0 0 0,6,12,18 ? * *';
String jobID = system.schedule('Merge Job', sch, m);


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
CooldayCoolday
global class UpdateBatchSchedule implements Schedulable{
    global void execute(SchedulableContext ctx) {
        UpdateBatch p = new UpdateBatch();
        database.executeBatch(p,200);
        UpdateBatchSchedule j = new UpdateBatchSchedule ();
        String sch = '0 0 0,6,12,18 ? * MON-FRI';
        System.schedule('UpdateBatchScheduleJob', sch, j);
    }  
}

will this work ?
CooldayCoolday
Hi Sai,

I am getting this error 

Method does not exist or incorrect signature: void schedule(String, String, UpdateBatch) from the type System
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

I have updated the code can you check my previous answer.

Thanks,
 
CooldayCoolday
Hi @Sai Praveen

Do I have to run it every time in anonymous window?

Thanks
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

No it is not needed to run every time. If you run this once in each sandbox then this class will be scheduled every 6 hours like I mentioend above.

Thanks,
 
CooldayCoolday
Hi ,

What about production?

Thanks and Regards
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Yeah it will be same in production as well. You have to run this once in production as well.


Thanks,

 
CooldayCoolday
Thank you so much for helping.