You need to sign in to do that
Don't have an account?

How do I create a trigger to count the number of open cases on an account
All,
I need to create trigger to count the number of open cases on an account. I need to display this information on the account page.
Thanks for the help,
Michael
Hi,
here is the example to count number of cases in Account through trigger
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
The trigger works great to count the total number of cases on an account
but I need to only count the open cases. Could you please include that in
the trigger?
Thanks,
Michael
* *
*Michael Lindsay*
Sales Enablement Manager
Office: 408-962-3914 | Mobile: 408-718-7524
*www.picarro.com*
*World's Leading Instruments* *for Carbon and Water Cycle Measurements*
Hi Michael,
below is the updated trigger.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
I am trying to do something similar for an application called RemedyForce which is a Service Desk application. I am wanting to find the number of Incidents (BMCServiceDesk__Incident__c) created against a User (BMCServiceDesk__FKClient__c) and store it in a cutom field (IncidentCount__c)
How would adapt the trigger above to do this?
Thanks
Sonya
trigger tskUpdatetrigger on BMCServiceDesk__Incident__c(after insert, after update,after delete) {
02 List<BMCServiceDesk__Incident__c> lstIncident = [select id, BMCServiceDesk__FKClient__c from Incident where id in: trigger.newmap.keyset()];
03 set<Id> sBMCServiceDesk__FKClient__c = new set<Id>();
04 for(Incident in: lstIncident){
05 if(in.BMCServiceDesk__FKClient__c != null){
06 sBMCServiceDesk__FKClient__c.add(in.BMCServiceDesk__FKClient__c);
07 }
08 }
09 if(sBMCServiceDesk__FKClient__c != null && sBMCServiceDesk__FKClient__c.size() > 0){
10 List<BMCServiceDesk__FKClient__c> lstClient = [select id, IncidentCount__c, (select id from Cases where status = 'Open') from Account where id in: sAccId];
11 if(lstClient.size() > 0){
12 for(Account acc: lstClient){
13 acc.IncidentCount__c= acc.Cases.size();
14 }
15
16 update lstIncident;
17 }
18 }
19 }
Thank you so much for this trigger, however I am getting a 'de-reffrencing a null object' error in line 2 column 1 when deleting the case only. The only change I made is status ='Open' changed to status !='Closed'. I am a novice when it comes to triggers - can you please help?
Much appreciated,
Brian