I am trying to abort Salesforce schedule job using below script

list<CronTrigger> con=[SELECT CreatedById,CreatedDate,CronExpression,CronJobDetailId,EndTime,Id,LastModifiedById,NextFireTime,OwnerId,PreviousFireTime,StartTime,State,TimesTriggered,TimeZoneSidKey FROM CronTrigger where State='ACQUIRED'];

for(CronTrigger ct:con)

But Getting below EXCEPTION:

EXCEPTION: System.StringException: Invalid parameter value "000000000000000" for parameter "id". STACKTRACE: AnonymousBlock: line 4, column 1 LINE: 4 COLUMN: 1

Findings : 1) CRONJOBDETAILID is null for these job records. 2) DML operation DELETE not allowed on CronTrigger.

Any Help??

  • try like this List<CronTrigger> jobsToAbort = [select Id from CronTrigger where CronJobDetail.JobType = '7']; for (CronTrigger job : jobsToAbort) { System.abortJob(job.Id); } Mar 23 '15 at 10:17
  • @KiranMutturu, As mentioned in question, CRONJOBDETAILID is null for these job records. Also All CRONJOBDETAIL records in my org are of Type='7', So it would abort all of the jobs. [Not the desired result:(]
    – Vishal_kdn
    Mar 23 '15 at 10:57
  • if this is not the case you need to go with the job names only to refer the scheduled jobs here is the link docs.releasenotes.salesforce.com/en-us/winter14/release-notes/… Mar 23 '15 at 12:49
// loop through jobs located by name that we need to abort
for(CronTrigger ct : [SELECT Id, CronJobDetail.Name, CronJobDetail.JobType FROM CronTrigger WHERE CronJobDetail.Name like 'WorkOrder%'])
  // abort the job, try/catch because the job might not exist
    catch (exception e) {}

Got the solution for this query from SF support(they just deleted the job instance from backend).

Thanks for the Help Guys:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.