How to schedule a class to run once at a specific time from apex

Salesforce gives out of the box ability to schedule apex classes with some limited options to control frequency under setup => apex classes => "Schedule Apex" button. But this approach limits you to run apex classes only at the start of the hour.

If you have a need to run a scheduled apex class at a specific time, you can use custom CRON expressions gives a more flexible way to do that.


Note that nextRun can be any datetime value in this case. Here we generate a cron expression from the datetime provided. If you want to read more about cron expressions refer this blog.

No comments:

Post a Comment