Ask Search:
Jason WangJason Wang 

Apex Scheduler

If i want to run apex class per 2 hours. How do i set arg 2 of the method System.Schedule(arg 1, arg 2, arg 3) ???
I don't understand that mean of the characters format of argument 2 at all.
Best Answer chosen by Jason Wang
Neeraj SethiNeeraj Sethi
Hye Jason,

You can Scheduler a class in two hours with following cron expression.
0 0 1/2 ? * *
Please try and let me know if any query.

Hope this will help. 

Thanks
Neeraj Sethi
 

All Answers

Patrick LEBRETTEPatrick LEBRETTE
Hi Jason,

as per specification https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm, with arg2 tou can specify (in that order :
Seconds
Minutes
Hours
Day_of_month
Month
Day_of_week
optional_year

Examples:
0 0 13 * * ? : Class runs every day at 1 PM.
0 0 22 ? * 6L : Class runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRI : Class runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010 : Class runs every day at 8 PM during the year 2010.

I am not sure you can do in a one-command line a schedule to execute each 2 hours. It is designed to execute on a daily, weekly or a monthly basis at specific hours.

Regards
Neeraj SethiNeeraj Sethi
Hye Jason,

You can Scheduler a class in two hours with following cron expression.
0 0 1/2 ? * *
Please try and let me know if any query.

Hope this will help. 

Thanks
Neeraj Sethi
 
This was selected as the best answer