You need to sign in to do that
Don't have an account?
Depton
SOQL for loop help
/* Provide summary of Number of Cases on Contacts record */ trigger CaseSumTrigger on Case(after delete, after insert, after undelete, after update) { Case [] cas; if (Trigger.isDelete) cas= Trigger.old; else cas= Trigger.new; // get list of Contacts Set<ID> contIds = new Set<ID>(); for (Case cs : cas) { contIds.add(cs.ContactId); } Map<ID, Case> CasesForContacts = new Map<ID, Case>([select Id ,ContactId from Case where ContactId in :contIds]); Map<ID, Contact> contToUpdate = new Map<ID, Contact>([select Id ,items__c from Contact where Id in :contIds]); for (Contact cont: contToUpdate.values()) { Set<ID> casIds = new Set<ID>(); for (Case cs : CasesForContacts.values()) { if (cs.ContactId == cont.Id) casIds.add(cs.Id); } if (cont.items__c != casIds.size()) cont.items__c = casIds.size(); } update contToUpdate.values(); }
How/Where do i add the loop to get only CLOSED cases?
Thank you!
All Answers
Just change your first for loop like this:
Thank you!
might be something wrng in the code, it was working, then I have added yours, and now is not working
I am checking but any help would be really appreciated!
I just want to have a total number of cases open on the contact record!:)