Code
Apex Class:
global class UpdateCases implements Database.Batchable<SObject>{
global final String query;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Case> scope) {
for(Case cs : scope){
if(cs.Status=='New'){
cs.Priority='High';
}
}
update scope;
}
global void finish(Database.BatchableContext bc) {
AsyncApexJob job = [select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email From AsyncApexJob where Id = :bc.getJobId() ];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddress = new String[]{job.CreatedBy.Email};
mail.setToAddresses(toAddress);
mail.setSubject('Apex job Status' + job.Status);
mail.setPlainTextBody('The apex job processed ' + job.TotalJobItems + ' Batches with ' + job.NumberOfErrors + ' failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
Apex Code (Execution):
UpdateCases objA = new UpdateCases();
objA.query = 'SELECT Id, Status,Priority FROM Case';
Database.executeBatch(objA,100);
Video
Video does not exists.