Use Apex Scheduler for regular maintenance tasks
- johnsontitus
- May 21, 2020
- 1 min read
To invoke Apex classes to run at specific times, first implement the Schedulable interface for the class.
Then, schedule an instance of the class to run at a specific time using the System.schedule method.
Implement the execute method of this interface.
Refer to the following for implementation - https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_scheduled
use the System.Schedule method to execute it.
The System.Schedule method takes three arguments:
a name for the job,
a CRON expression used to represent the time and date the job is scheduled to run,
and the name of the class.
eg:
<Schedule Apex class name> reminder = new <Schedule Apex class name>();
// Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
String sch = '20 30 8 10 2 ?';
String jobID = System.schedule('Remind Opp Owners', sch, reminder);

Comments