System.StringException thrown when aborting a job in a rest controller
Welcome to the world of known issues :
https://success.salesforce.com/issues_view?id=a1p30000000SyhIAAS
As rao said, there is a SF known issue preventing jobs from being aborted in a custom rest controller.
Here is a simplified version of my job's execute method:
public void execute(SchedulableContext SC) {
//configUtil.getState() retrieves the custom setting with the 'RUNNING'/'STOPPED' state information.
if(configUtil.getState() != 'RUNNING'){
//abort the current job, and return.
System.abortJob( SC.getTriggerId() );
return;
}
//do stuff
coolMethodThatDoesCoolStuff();
//reschedule job to run again in 1 minute
Datetime sysTime = System.now().addSeconds(60);
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
System.schedule( 'AmbitionPusherSelfSchedule' + sysTime, chronExpression, new Pusher() );
//abort the current job instead of running again in an hour.
System.abortJob( SC.getTriggerId() );
}
and here is the code from the controller:
@HttpDelete
global static String stop(){
configUtil.setState('STOPPED');
return 'job stop requested';
}