I have created the batch class which will store the count in other object with status "New" and "Closed" I have 60 Case records with 25 as "New" status and remaining with "Closed" status
when i am running batch of 25 then my count is coming 0 for "New".
because in 3rd batch there is no record with "New" status Values.Please suggest how to tackle this.
global class CaseBatchApex implements Database.Batchable<sObject>, Database.Stateful {
global List<string>lstcount;
global List<integer>lstcount1;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID, status FROM case');
}
global void execute(Database.BatchableContext bc, List<case> scope){
integer count2;
Map<case,string> casemap=new Map<case,string>();
Map<case,string> casemap1=new Map<case,string>();
System.debug('Scope>>>'+scope);
for(case c:scope){
if(c.status=='New'){
casemap.put(c,c.Status);
}
else if(c.status=='Closed'){
casemap1.put(c,c.Status);
}
}
lstcount=new list<string>([select count() from case where status in:casemap.values()]);
lstcount1=new list<integer>([select count() from case where status in:casemap1.values()]);
CaseCount cse=new CaseCount();
cse.id='a077F000001pAxb';
cse.New_Status_count__c=string.valueof(lstcount.size());
cse.Closed_Status_Count__c=string.valueof(lstcount1.size());
update cse;
}
global void finish(Database.BatchableContext bc){
}
}