You need to sign in to do that
Don't have an account?
System.abortJob() not working in UninstallHandler script
I have a package which creates a scheduled job using a post-install script, and saves the id in a custom settings entry. I am trying to create the equivalent uninstall script, but not having much success. The class and associated tests all perform normally when I run them in the IDE. When I run them from the Web UI however, the abortJob call doesn't delete the job and my tests fail. If I comment out the tests and do an actual install and uninstall of the package, the scheduled job is not deleted.
Any idea why this would happen? I know that the documentation indicates that uninstall scripts cannot schedule new jobs, call @future methods, etc, but it doesn't mention anything about deleting existing jobs. The same code, when part of a controller for a settings page, worked fine. Maybe I am misintepreting when the uninstall script actually runs, meaning the only option is for an admin to delete the scheduled job manually, before trying to uninstall the package?
Code snippet:
...
if(settings != null) {
try {
system.debug('Removing scheduled job with id: ' + settings.scheduled_job_id__c);
System.abortJob(settings.scheduled_job_id__c);
} catch (Exception e) {
system.debug('Error removing scheduled job: ' + e.getMessage());
}
delete settings;
}
...
Not sure if you have resolved this yourself but the issue is that the uninstall script runs after the package is uninstalled, not before.
Had a similar issue and resolved it by creating a button that called the abort code to allow the schedule to be deleted, rather than leave to sys admin to do.