0

I have a request to check how many calls were made to each contact on my org until they answered the phone.

Infrastructure: The Call__c object has a lookup field called ContactLookup__c that points to the standard Contact object.

So for example, I have a contact named 'James' and the contact has 3 records of Calls (Call__c):

1st Call - status = no answer

2nd call - status = no answer

3rd call - status = answered

How can I create a SOQL query to group the calls by contact name, and then check if one of these calls has a status of "answered"?

I tried to use aggregateResults but I only managed to get a list of how many call records there are per contact, but I can't seem to check the status for each call

List<AggregateResult> records = [SELECT ContactLookup__r.Name,count(id) conId
                                 FROM Call__c 
                                 GROUP BY ContactLookup__r.Name];
1
  • How about querying child records using inner query? Sep 17, 2020 at 14:32

1 Answer 1

1

Could try adding an extra grouping for the call status

List<AggregateResult> records = [SELECT ContactLookup__r.Name, Status__c, count(id) conId
                                 FROM Call__c 
                                 GROUP BY ContactLookup__r.Name, Status__c];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .