+ Start a Discussion
klocworkklocwork 

Works in sandbox but fails @ Validation in Production

Help please ...

 

Working on my 3rd ever trigger and I am having a mysterious issue.  

 

I've used this code twice before with no incident to roll up counts from related objects.  When I modified this code to update Case with a count of Comments it works fine in my sandbox, but when I validate it in Production I get the following:"Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TicketRollUpCountPublicComments: execution of AfterInsert caused by: System.QueryException: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch Trigger..."

 

Is there an obvious error I am not seeing?  Any thoughts would be awesome! 

 

trigger TicketRollUpCountPublicComments on CaseComment (after insert, after update) {

set<Id> ParentIds = new set<Id>();


if(trigger.isInsert || trigger.isUpdate){
for(CaseComment c : trigger.new){
ParentIds.add(c.ParentId);
}
}


if(trigger.isDelete){
for(CaseComment c:trigger.old){
ParentIds.add(c.ParentId);
}
}

map<Id,Double> CaseMap = new map <Id,Double>();


for(aggregateResult q:[select count(Id), ParentID
from CaseComment where (CaseComment.IsPublished != FALSE) group by ParentId]){
CaseMap.put((Id)q.get('ParentId'),(Double)q.get('expr0'));
}

List<Case> CasesToUpdate = new List<Case>();


for(Case cs:[Select ID, Number_of_Comments__c from Case where Id IN :ParentIds]){
Double UserSum = CaseMap.get (cs.Id);
cs.Number_of_Comments__c=UserSum;
CasesToUpdate.add(cs);
}

update CasesToUpdate;
}

osamanosaman

The problem is because of the query. You should try doing it without using aggregate result query.

 

select count(Id), ParentID from CaseComment where (CaseComment.IsPublished != FALSE) group by ParentId

 

You should try doing it without using aggregate result query.