You need to sign in to do that
Don't have an account?
Pathikrit
Scheduling Troubles with Batch Apex
Hi Guyz,
I am running into a scheduling problem with my apex class. I have a batch apex class named 'MyBatchApex' which I want to schedule to run every 5 minutes. I created a class with implements the Schedulable interface and here goes the code..
To schedule this, I am running the following snipper from Developer Console
The job creates a async job and executes the batch after 5 mins as expected and then stops to run. I want this to execute every 5 minutes like a cron job. Am I doing anything wrong here? How to acheive a frequency of 5 min execution then?
I am running into a scheduling problem with my apex class. I have a batch apex class named 'MyBatchApex' which I want to schedule to run every 5 minutes. I created a class with implements the Schedulable interface and here goes the code..
global class MySchedulerClass{ global void execute(SchedulableContext sc) { ID BatchId = Database.executeBatch(new MyBatchApex(), 50); } public static void scheduleThis(){ String cronString='0 5 * * * ?'; System.schedule('MyJob', cronString, new MySchedulerClass()); } }
To schedule this, I am running the following snipper from Developer Console
MySchedulerClass.scheduleThis()
The job creates a async job and executes the batch after 5 mins as expected and then stops to run. I want this to execute every 5 minutes like a cron job. Am I doing anything wrong here? How to acheive a frequency of 5 min execution then?
For your scenario, you will need 12 schedules as follows.
cronString='0 5 * * * ?';
cronString='0 10 * * * ?';
cronString='0 15 * * * ?';
cronString='0 20 * * * ?';
cronString='0 25 * * * ?';
cronString='0 30 * * * ?';
cronString='0 35 * * * ?';
cronString='0 40 * * * ?';
cronString='0 45 * * * ?';
cronString='0 50 * * * ?';
cronString='0 55 * * * ?';
cronString='0 00 * * * ?';
Regards,
Vivek Patel.
Please like or mark as best answer if this resolves your issue to benefit others finding the correct answer and improve the quality of developer forum.
All Answers
When I try to to run the job a second time from Developer Console, I get the following exception:
system.asyncexception: MyJob is already scheduled for execution
Again, when I query the ApexAsyncJob object, I don't see any jobs scheduled, queued or aborted...
The cron expression you're looking for would be "0 0/5 * * * ?"
(taken from http://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm)
Thanks for that. I thought I was doing something wrong.
I tried the cron expression you provided and I'm getting this error while running this from Developer Console.
System.StringException: Seconds and minutes must be specified as integers: 0 0/5 * * * ?
Any idea on this?
For your scenario, you will need 12 schedules as follows.
cronString='0 5 * * * ?';
cronString='0 10 * * * ?';
cronString='0 15 * * * ?';
cronString='0 20 * * * ?';
cronString='0 25 * * * ?';
cronString='0 30 * * * ?';
cronString='0 35 * * * ?';
cronString='0 40 * * * ?';
cronString='0 45 * * * ?';
cronString='0 50 * * * ?';
cronString='0 55 * * * ?';
cronString='0 00 * * * ?';
Regards,
Vivek Patel.
Please like or mark as best answer if this resolves your issue to benefit others finding the correct answer and improve the quality of developer forum.
"0 */5 * * * ?"
I had faced the similar problem and that's the only resolution available I think, other cros expression do not work in salesforce, they are okay for java or other language.
Regards,
Vivek Patel.
Please like or mark as best answer if this resolves your issue to benefit others finding the correct answer and improve the quality of developer forum.
This expression doesn't seem to work in Apex. I have previously worked on Java and used cron expression like this before. But Apex throughs error (System.StringException: Seconds and minutes must be specified as integers: 0 */5 * * * ?) when you try to use this as your cron expression.
Can you give a little insight on how were you able to do this?
I guess that is the only way for me now. Thanks for the help.