我apex
为案例升级编写了一个批处理类。我想为它写一个测试类。有人可以帮帮我吗。下面是我写的代码:
global class CaseEscalation implements Database.Batchable<SObject>
{
global CaseEscalation()
{
}
global Database.QueryLocator start(Database.BatchableContext ctx)
{
System.debug('checking=======');
return Database.getQueryLocator([SELECT CaseNumber, CreatedDate,Status FROM Case where (Status!='Closed' AND Status!='Escalated') and CreatedDate<TODAY ]);
}
global void execute(Database.BatchableContext ctx, List<Sobject> scope)
{
List<Case> ca = (List<Case>)scope;
System.debug('checking======='+ca);
for(Case c : ca)
{
System.Debug(c);
String emailMessage = 'The case ' + c.CaseNumber + ' has been ecalated ' + ' Please look into the case ' + 'Thankyou';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'reems.agarwal3@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Case Escalation');
mail.setPlainTextBody(emailMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });
c.Status = 'Escalated';
}
if(ca.size()>0)
update ca;
}
global void finish(Database.BatchableContext ctx)
{
}
}