Below is an example batch job that you can use to close cases. This batch job can be executed using command "Database.executeBatch(new BatchCloseCase ());"
global class BatchCloseCase implements Database.Batchable<sObject> { public String query = 'select id, status from case where CreatedBy.Name=\'Automated Process\' and status != \'Closed\'';
global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); }
global void execute(Database.BatchableContext BC, List<sObject> scope) { List<Case> lstCase = new List<Case>(); for(Sobject o : scope) { Case C = (Case) o; C.Status = 'Closed'; lstCase.add(C); } update lstCase; }
global void finish(Database.BatchableContext BC){ } }
Below is an example batch job that you can use to close cases. This batch job can be executed using command "Database.executeBatch(new BatchCloseCase ());"
global class BatchCloseCase implements Database.Batchable<sObject> {
public String query = 'select id, status from case where CreatedBy.Name=\'Automated Process\' and status != \'Closed\'';
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
List<Case> lstCase = new List<Case>();
for(Sobject o : scope)
{
Case C = (Case) o;
C.Status = 'Closed';
lstCase.add(C);
}
update lstCase;
}
global void finish(Database.BatchableContext BC){
}
}