Skip to content

Instantly share code, notes, and snippets.

@rtconner
Last active July 18, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtconner/7fd9b78d4f2550bca77d1265f8b07aa3 to your computer and use it in GitHub Desktop.
Save rtconner/7fd9b78d4f2550bca77d1265f8b07aa3 to your computer and use it in GitHub Desktop.
Delete All Batch Jobs
global class deletebatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
string txt = 'Bulk Convert Lead Batch';
String query = 'SELECT Id, CronJobDetail.Id, CronJobDetail.Name, CronJobDetail.JobType FROM CronTrigger WHERE CronJobDetail.Name LIKE \'Bulk Convert Lead Batch%\' LIMIT 150';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<crontrigger> scope) {
for(crontrigger a : scope)
{
system.abortJob(a.id);
}
}
global void finish(Database.BatchableContext BC) {
DateTime nextBatchTime = System.Now().addMinutes(1);
String chronExpression = '' + nextBatchTime.second() + ' ' + nextBatchTime.minute() + ' ' + nextBatchTime.hour() + ' ' + nextBatchTime.day() + ' ' + nextBatchTime.month() + ' ? ' + nextBatchTime.year();
batchitupson_schedule clsCRON = new batchitupson_schedule();
System.Schedule( 'deletebatch ' + nextBatchTime, chronExpression, clsCRON);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment