| 1. |
How To Schedule A Class In Apex? |
|
Answer» To invoke Apex classes to run at specific times, first implement the Schedulable interface for the class, then specify the schedule using either the Schedule Apex page in the Salesforce user interface, or the System.schedule method. After you implement a class with the Schedulable interface, use the System.Schedule method to execute it. The SCHEDULER runs as system: all classes are executed, whether the user has PERMISSION to execute the class or not. The System.Schedule method takes three arguments: a name for the job, an EXPRESSION used to represent the time and date the job is scheduled to run, and the name of the class. Salesforce only adds the process to the queue at the scheduled time. Actual execution may be delayed based on service availability. The System.Schedule method uses the user's time zone for the BASIS of all schedules. You can only have 25 classes scheduled at one time. Example Code: String CRON_EXP = '0 0 * * * ?'; clsScheduledHourly sch = new clsScheduledHourly(); system.schedule('Hourly Sync', CRON_EXP, sch); To invoke Apex classes to run at specific times, first implement the Schedulable interface for the class, then specify the schedule using either the Schedule Apex page in the Salesforce user interface, or the System.schedule method. After you implement a class with the Schedulable interface, use the System.Schedule method to execute it. The scheduler runs as system: all classes are executed, whether the user has permission to execute the class or not. The System.Schedule method takes three arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the name of the class. Salesforce only adds the process to the queue at the scheduled time. Actual execution may be delayed based on service availability. The System.Schedule method uses the user's time zone for the basis of all schedules. You can only have 25 classes scheduled at one time. Example Code: String CRON_EXP = '0 0 * * * ?'; clsScheduledHourly sch = new clsScheduledHourly(); system.schedule('Hourly Sync', CRON_EXP, sch); |
|