Salesforce Apex Scheduler

To schedule an Apex class to run at some regular intervals, first write an Apex class that implements the Salesforce-provided interface Schedulable.

The scheduler runs as system: all classes are executed, whether the user has permission to execute the class or not. For more information on setting class permissions, see “Apex Class Security Overview” in the Salesforce online help.

To monitor or stop the execution of a scheduled Apex job using the Salesforce user interface, go to Setup –> Monitoring –> Scheduled Jobs. For more information, see “Monitoring Scheduled Jobs” in the Salesforce online help.

The Schedulable interface contains one method that must be implemented, execute.

global void execute(SchedulableContext sc){}

Example:

global class SampleSchedulerClass implements Schedulable {

    global void execute( SchedulableContext SC ) {
       
    }
	
}

To schedule the Apex Class, go to Setup –> Develop –> Apex Classes and then click “Schedule Apex” button.

Figure clearly explains how to schedule Batch Apex. The frequency may be set to Weekly or Monthly. Start and End dates are important. Preferred Start Time is also important. The job will be sent to Apex Job queue. The preferred Start Time won’t be the exact time because it depends upon the job queue. The job will be executed after other jobs in the job queue have been executed.

Leave a Reply