Any thoughts on why the removeExistingCompletedJobs Method suddenly stopped working around March 2015? I'm not sure if it coincided with Spring '15 release or not as I wasn't watching closely. Code done by another developer bit over my head with the Cron stuff but I understand it a little.
I know there are other ways to remove scheduled jobs but this had been working fine for past 18 months. Classes are using API 31.0.
Submitted a case but Support hasn't been too helpful since this is in Production so I had to comment out code as a workaround (uncommented here).
global void execute(SchedulableContext SC){
queryBalance();
removeExistingCompletedJobs(sc);
scheduleNewJobs(sc);
//Schedule a new batch to retrieve Existing Assignments
startBatchToRetrieveAssignments();
//Schedule a new batch to mark assigments as approved or rejected
startBatchApproveAssignments();
startBatchToDeleteHit();
}
//=========================================================================//
//Find new jobs and schedule them in the Queue
//=========================================================================//
for(Schedule__c schedule :lstSchedule){
schedule.Schedule_Job_Name__c = getJobName(schedule);
schedule.Schedule_Job_Created__c = true;
MturkScheduleJobPoster mturkJobPoster = new MturkScheduleJobPoster(schedule.ID);
**Id jobID = System.schedule(schedule.Schedule_Job_Name__c, getCronExpression(schedule),
mturkJobPoster );
schedule.Schedule_Job_ID__c = jobID;**
}
public void removeExistingCompletedJobs(SchedulableContext SC) {
List<Schedule__c> lstSchedule = [SELECT Name, Schedule_Job_ID__c
FROM Schedule__c
WHERE Schedule_Job_Completed__c = true
AND Schedule_Job_ID__c != null
AND StartDateTime__c < :System.now()
Limit 100];
for(Schedule__c schedule :lstSchedule){
System.abortJob(schedule.Schedule_Job_ID__c);
schedule.Schedule_Job_ID__c = null;
schedule.Schedule_Job_Completed__c = false;
schedule.Schedule_Job_Created__c = false;
schedule.Schedule_Job_Name__c = null;
}
update lstSchedule;
}