Sample code:
SampleSchedulableClass obj = new SampleSchedulableClass();
String cron = ‘0 59 * * * *’
System.schedule(‘Testing’, cron, obj);
The above code executes SampleSchedulableClass for every one hour.
Syntax for Cron:
Seconds Minutes Hours Day Month Week Year
Seconds : 0 – 59
Minutes : 0 – 59
Hours : 0 – 23
Day : 1 – 31
Month : 1 – 12
Week : 1 – 7(Sunday is first and Saturday is last)
Year : upto 2099
Year is optional.
Expression
|
Description
|
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.
|
? – No value
* – All values
L – Last
W – Nearest weekday
Cheers!!!