You need to sign in to do that
Don't have an account?
Raj R.
How to schedule a Schedulable class to run every hour?
Hi, I have the following schedulable class below and i wanted to be able to schedule it to run at 12am through the UI by navigating to schedule apex and then setting it to run every day at 12am. However, after this job has ran, i want it to schedule a subsequent job (same class) to run in the next hour. Is this possible?
The goal is to only schedule it through the UI to run at 12 Am and then it will automatically schedule the remaining jobs 1 hour later.
global class SampleClass implements Schedulable{ global void execute(SchedulableContext alistContext) { Database.executeBatch('myBatchClass', 100); //when database executebatch is done, I want to schedule the same job 1 hour later String cron_exp = '0 0 1 * * ?'; String jobName = 'somename'; System.Schedule(jobName, cron_exp, new SampleClass()) } }
Hi,
What you need to do is:
1. Instead of rescheduling it in Schedule Class you should reschedule it in final method of the the myBatchClass
2. Just put following code in your final method of the batch class
You can read this blog for more infomration https://corycowgill.blogspot.in/2010/12/leveraging-scheduled-apex-to-link-batch.html
Thanks
Shashikant
All Answers
Hi,
What you need to do is:
1. Instead of rescheduling it in Schedule Class you should reschedule it in final method of the the myBatchClass
2. Just put following code in your final method of the batch class
You can read this blog for more infomration https://corycowgill.blogspot.in/2010/12/leveraging-scheduled-apex-to-link-batch.html
Thanks
Shashikant
What happens when the Database.executeBatch spawns several instances of the batch class up to 100 records? Will it schedule only 1 or won't it schedule for every batch "sub process" that is created?
final method of a Batch is executed only once in complete Batch execution once all batch executions are processed. So say there are 1000 records and batch size is 10 then there would be 100 batch will be executed with 10 records in each. But still final will only execute once after all 100 executions are done so it will only schedule next job only once.
I hope above answers your question.
Thanks
Shashikant
Yes that answers my questions and resolved my concern. Thank you very much.
P.S. It's free
Thank you for the code and blog link you provided.This helped me as well.I have one more question.So according to the code I suppose the batch process runs every hour without break.is that correct.I mean this is what I am trying to achieve.But what if I have to stop the job from running in the next hour?
Thank you
Ankita