Developing Schedulable Code

An Apex class that can be scheduled by Force.com must implement the Schedulable interface. The interface requires no methods to be implemented; it simply indicates to the platform that your class can be scheduled. Code that is executed by the scheduler runs as the system user, so sharing rules or other access controls are not enforced. At most, ten classes can be scheduled at one time.

The class in Listing 9.8 enables the Batch Apex example from Listing 9.1 to be schedulable. It does this by implementing the Schedulable interface, which has a single method: execute. Although you could implement this interface directly on your batch class, the best practice recommended by Salesforce is to create a separate Schedulable class.

Listing 9.8 Schedulable Batch Apex


global class Listing9_8 implements Schedulable {
  global void execute(SchedulableContext sc) {
    Listing9_1 batch = new Listing9_1();
    Database.executeBatch(batch);
  }
}


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.173.78