Contact Us:

670 Lafayette Ave, Brooklyn,
NY 11216

+1 800 966 4564
+1 800 9667 4558

If there is a need of scheduling an apex job or schedulable apex class after each hour then cron expression is the best way. Cron expression allows you to schedule a job on a specific time. Following cron expression runs a job after each hour of the day.

[code language=”java”]
scheduledJob j = new scheduledJob();
String sch = ‘0 0 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 ? * *’;
System.schedule(‘My Job’, sch, j);
[/code]

Cron expression is built with following parameters - 
Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year

You can Special Characters in a Cron expression such as running a job only on weekdays after each 4 hours then following Cron expression will be used.
[code language=”java”]
scheduledJob j = new scheduledJob();
String sch = ‘0 0 0,4,8,12,16,20 ?  MON-FRI’;
System.schedule(‘My Job’, sch, j);
[/code]
For more details you can check the Salesforce Article.
 

Leave a comment

Your email address will not be published. Required fields are marked *