Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Last active December 19, 2015 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinohara80/5867465 to your computer and use it in GitHub Desktop.
Save kevinohara80/5867465 to your computer and use it in GitHub Desktop.
Repro code for Apex Summer '13 String/Id issue with System.abortJob(String);
global class ScheduledJob implements Schedulable {
global void execute(SchedulableContext sc) {
System.debug('Executing');
}
global static void schedule() {
ScheduledJob job = new ScheduledJob();
System.schedule('Test Job', '0 0 13 * * ?', job);
}
global static void unschedule() {
CronTrigger cron = [SELECT Id FROM CronTrigger LIMIT 1];
System.abortJob(cron.Id);
}
}
@RestResource(urlMapping='/unschedule')
global with sharing class ScheduledJobRest {
@HttpGet
global static void doGet() {
ScheduledJob.unschedule();
}
}
@kevinohara80
Copy link
Author

This is yet another String/Id related issue in Summer '13. This one has to do with using the System.abortJob() within an Apex REST request. The above code will reproduce the issue. Here are the steps.

  1. Schedule the ScheduledJob class. You can do this from the developer console using ScheduledJob.schedule().
  2. Using your favorite REST client, make an http GET to the /unschedule route above. That route will then attempt to unschedule the job using System.abortJob().

You will receive the following error on Summer '13:

System.StringException: entityId : U#233.3fffffff (CronJobDetail)

Notes:

  • We are only able to reproduce this when using Apex REST. If you were to write a unit test against the schedule and unschedule methods, they pass just fine. You also cannot reproduce this error using Anonymous Apex.
  • There have been numerous reports of String/Id issues within Apex in Summer '13. This looks to be another.

@kevinohara80
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment