You need to sign in to do that
Don't have an account?
Aborting multiple scheduled jobs is not deleting all the jobs
I have a scenario that creates 6 scheduled jobs so they run every ten minutes. I store the cron trigger id so I can delete all the jobs by clicking a button rather than delete one at a time in the Setup module's Scheduled Jobs page.
I try to spin through the six jobs and call system.abort for each one, one at a time. The debug logs show abort is called and there is no exception caught in my try block. The problem is only the first job is actually deleted.
Here is my code:
for(My_Setting__c setting : settings)
{
try
{
System.debug('--- Delete scheduled job with Job_Id = ' + setting.Value__c);
System.abortJob(setting.Value__c);
delete setting;
}
catch (Exception e)
{
System.debug('--- Unable to delete scheduled job with Scheduled_Geocoder_Job_Id = ' + setting.Value__c + ' because ' + e.getMessage());
}
}
The setting is deleted, but 5 of the 6 jobs remain.
Here is a snippet from the debug logs:
12:10:17.456 (341086000)|USER_DEBUG|[119]|DEBUG|--- Delete scheduled job with Scheduled_Geocoder_Job_Id = 08e500000000HRJAA212:10:17.456 (341126000)|METHOD_EXIT|[119]|System.debug(ANY)12:10:17.456 (341182000)|STATEMENT_EXECUTE|[120]|System.abortJob(String)12:10:17.456 (341223000)|METHOD_ENTRY|[120]|System.abortJob(String)12:10:17.474 (359183000)|METHOD_EXIT|[120]|System.abortJob(String)12:10:17.474 (359252000)|STATEMENT_EXECUTE|[122]|Delete: SOBJECT:Map_Setting__c12:10:17.474 (359321000)|HEAP_ALLOCATE|[122]|Bytes:812:10:17.474 (359365000)|DML_BEGIN|[122]|Op:Delete|Type:Map_Setting__c|Rows:112:10:17.474 (359514000)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:812:10:17.498 (383561000)|DML_END|[122]
Hi,
Instead of performing "delete setting" after abortJob(), try deleting the whole list "settings" after the for loop.
Not sure whether that exactly is the problem. But I had tried a similar code with the only difference being that I was deleting the whole list of Job Ids after the looping. So guess that might be the issue here.
Hope this helps.
Regards,
Lakshmi.