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.
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);
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.
scheduledJob j = new scheduledJob(); String sch = '0 0 0,4,8,12,16,20 ? MON-FRI'; System.schedule('My Job', sch, j);
For more details you can check the Salesforce Article.
I am certified Salesforce Developer with Sales and Service cloud certifications. I am a true believer in #GivingBack principle and a Salesforce enthusiast. I am working as a member of our #SalesforceOhana to learn and help other fellow Trailblazers of the community to grow and learn.
“I’m a true believer in karma. You get what you give, whether it’s bad or good.”