Skip to content

Instantly share code, notes, and snippets.

@jbro-io
Created January 28, 2013 23:06
Show Gist options
  • Save jbro-io/4660138 to your computer and use it in GitHub Desktop.
Save jbro-io/4660138 to your computer and use it in GitHub Desktop.
global class MassDelete implements Database.Batchable<sObject>
{
global final string query;
global MassDelete(String q)
{
query = q;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
delete scope;
}
global void finish(Database.BatchableContext BC)
{
AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
TotalJobItems, CreatedBy.Email
from AsyncApexJob where Id =:BC.getJobId()];
// Send an email to the Apex job's submitter notifying of job completion.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {a.CreatedBy.Email};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Sharing Recalculation ' + a.Status);
mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems +
' batches with '+ a.NumberOfErrors + ' failures.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment