I run this code in Developer console, Execute anonymous. How can I resolve this
Limit exception : Line: 1, Column: 1
System.LimitException: Too many query rows: 50001
I definitely have more than 50000 attachments. Any ideas would be highly appreciated.
Map<ID,Case> CaseMap = new Map<ID,Case> ([SELECT Id, Status FROM Case]);
List<Attachment> allAtt = [Select Id, ParentId FROM Attachment];
Integer closed = 0;
Integer withdrawn = 0;
Integer cancelled = 0;
for(Attachment att : allAtt){
Case getcase = CaseMap.get(att.ParentId);
if(getcase.Status == 'Closed'){
closed = closed + 1;
}
else if(getcase.status == 'Withdrawn'){
withdrawn = withdrawn + 1;
}
else if(getcase.status == 'Cancelled'){
cancelled = cancelled + 1;
}
}
system.debug('CLOSED Attachment count' + ' ' + closed);
system.debug('WITHDRAWN Attachment count' + ' ' + withdrawn);
system.debug('CANCELLED Attachment count' + ' ' + cancelled);
Attachment
records. Just remove the query.