Defining a schedulable Apex class
We define an Apex class that can be scheduled by implementing the Schedulable
interface. Similar to our Queueable
interface, it provides a single method, execute
, which we must implement. We can see this in the following code:
public class SchedulableExample implements Schedulable { public void execute(SchedulableContext SC) { //Do something } }
From the preceding code, we see that within the execute
method, it is the best practice to make a call to another class containing the logic we wish to run rather than explicitly declaring the logic within the execute
method itself. This primarily helps to ensure that you reuse code as much as possible and manage your separation of concerns, but this also makes the processing code easier to test by allowing you to test separately from the scheduled execution setup.
It is also important to recognize that our SchedulableExample...