function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kkr.devkkr.dev 

Count of all Contacts with Cases

Hi All,

 

     How to get the total count of all contacts  with atleast one related Case.

 

Thanks

Ispita_NavatarIspita_Navatar

hi,

Did you try the sub-query route?

hchhch

Use the following code:

 

list<case> casList = [select id, caseNumber,contactId from case];
system.debug('-----------'+casList.size());
set<id> casSet = new set<id>();
for(case c: casList){
casSet.add(c.contactId);
}
system.debug('-----------'+casSet.size());

 

"casSet.size()" contains the count of all cases with atleast one related case attached to it.

amidstcloudamidstcloud

HI hch,

 

I think contactid in not mandatory in th Case object.  I got  Zero list size

 

hchhch

If you get zero list size then there are no cases in your org. And if you get the set size as zero then there are no cases associated with the contact.