+ Start a Discussion
devloper sfdcdevloper sfdc 

how to get number of case created by contact group by account

Hi All,

I need soql query to retrive number of Cases created by Contact in an accounts.
VamsiVamsi
Hi,

Try the below and this should get you what you need.

List<Aggregateresult> sl = [select count(id),contact.LastName,Account.Name from case GROUP BY contact.LastName,Account.Name ];

Please mark as best answer if the above helps..!!!
 
devloper sfdcdevloper sfdc
Hi Vamsi,

Thanks for reply i need to update contact field total_no_of _case__c . it is posiblle?
<Saket><Saket>
Hi Developer SFDC 

Please find the solution below 
 
for(AggregateResult ar : [select count(Id) cou,ContactId from Case where ContactId in : ContactIdSet Group By ContactId])
    {
       
    }

where ContactIdSet is a set of contacts id for which u want to count the cases related to it

Thanks . 
<Saket><Saket>
Hi Developer SFDC 

Please let us know whether ur problem is solved or not?