I'm looking to implement a class that I can schedule every 5 minutes. This class will carry out some basic monitoring activity. But in order to know what to monitor, my scheduled class will need to keep some minimum amount of data in order to maintain state.
As recommended by sfdcfox, I could store most of my data in a record. But I'd need some sort of ID/key to access that record, and THAT needs to persist across executions.
I've referenced this link for handling the 5 minutes scheduling (is this the only way? Seems tedious...), however I'm not sure how to maintain state. If I initialize an object of the schedulable class by passing some data to the constructor and storing it in instance variables, can I access that as and when I want? For example:
global class SchedulableClass implements Schedulable
{
private String p1;
private String p2;
global SchedulableClass(String p1, String p2) {
this.p1 = p1;
this.p2 = p2;
}
global void execute(SchedulableContext ctx) {
System.debug(p1);
System.debug(p2);
}
}
...and now
SchedulableClass s = new SchdulableClass('test1', 'test2');
System.schedule('...', chronExp, s);
Thanks for the help.