Created
January 28, 2013 23:06
-
-
Save jbro-io/4660138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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