I am trying to create a count summary of all calls logged by a specific sales rep (as Task) for each of his prospects (e.g. 8 calls for prospect A, 14 for B, etc.) using Apex.
Below is what I got so far, unfortunately, Salesforces complains: "Too many SOQL calls":
List<Contact> prospects = [SELECT id FROM Contact WHERE OwnerId = '00651000003CWWpAAO'];
for(Contact c: prospects){
List<AggregateResult> countResult = [SELECT COUNT(Activity_Type__c) FROM Task WHERE WhatId = :c.Id AND Activity_Type__c = 'Call'];
System.debug(countResult[0].get('expr0'));
}
What's a better way to approach this and get the desired data?