How do I develop in a class that is referenced in a scheduled job?You will see the following error when you try to save this class:
This schedulable class has jobs pending or in progress
There is the workaround, what I did is create a Job scheduler so basically 1 scheduled class from where I reference all my scheduled classes. We are not initializing the class by creating a object of the class by name:
global class App_Job_Scheduler implements Schedulable {
global void execute(SchedulableContext sc) {
System.Type closedAccountsScheduler = Type.forName('Job_Closed_Accounts');
Schedulable closedAccountObject = (Schedulable)closedAccountsScheduler.newInstance();
closedAccountObject.execute(sc);
}
}
Scheduler class, now you can schedule this class and will not get the >This schedulable class has jobs pending or in progress error when you try to save any code to App_Service or Selector_Financial_Account
global class Job_Closed_Accounts implements System.Schedulable, Database.Batchable<SObject>, Database.Stateful, Database.AllowsCallouts {
global Database.QueryLocator start(Database.BatchableContext BC) {
return App_Selector_Financial_Account.newInstance().selectAccountAndRelatedObjectsToDelete();
}
global void execute(Database.BatchableContext BC, List<Financial_Account__c> financialAccountIdsToBeDeleted) {
List<Financial_Account__c> financialAccountsToDelete = App_Selector_Financial_Account.newInstance().selectAccountAndRelatedObjectsToDelete(financialAccountIdsToBeDeleted);
App_Service.instance.deleteRelatedAccountsRecords(financialAccountsToDelete);
}
global void finish(Database.BatchableContext BC) {}
}