My post-install script is failing on just one sandbox, and I can't figure out why. It has been working successfully for more than a year, on a number of different orgs, but this one fails. When it fails, I don't get any other details beyond the simple message "The post install script failed."
Here's my script:
public without sharing class ApiInstallHandler implements InstallHandler, UninstallHandler {
public void onInstall(InstallContext context) {
ApiSentinelRunLaterScheduled.scheduleSelf('');
}
public void onUninstall(UninstallContext context) {
ApiSentinelRunLaterScheduled.cancelSelf('');
}
}
And then, the dependent class:
// Sweeps up any sentinels that we couldn't start because they were
// triggered from a Batch or Future context. Time-based workflow
// would make more sense, but cannot be added to a managed package
public class ApiSentinelRunLaterScheduled implements Schedulable {
private static String jobName = 'API Sentinel Run Later';
public void execute(SchedulableContext SC) {
NebulaApiWorker.runLaterWorkers();
}
public static void cancelSelf(String namePrefix) {
List<CronTrigger> existingToCancel = [SELECT Id, CronJobDetail.Name, State
FROM CronTrigger
WHERE CronJobDetail.Name LIKE :namePrefix + jobName + '%'
AND CronJobDetail.JobType = '7'
AND State != 'DELETED'];
for(CronTrigger t : existingToCancel) {
System.abortJob(t.Id);
}
}
public static void scheduleSelf(String namePrefix) {
cancelSelf(namePrefix);
ApiSentinelRunLaterScheduled asr = new ApiSentinelRunLaterScheduled();
// every 15 minutes
for(integer i=0; i < 4; i++) {
String minutes = '' + (i*15);
System.schedule(namePrefix + jobName + ' (' + minutes + ')', '0 ' + minutes + ' * * * ?', asr);
}
}
}
Any ideas about how I can attack this? One obvious thing is to make a version of the package with a try..catch and then log the errors. But is there anything else to try before I go through that laborious process?
CronTrigger
table. Try clearing it in the problematic org, also, try running this code manually on the org