I want to count records based on different values provided to records using Status__c
field. Status__c
is a picklist field. For efficiency purpose, I want to run one query but get different result of counts of records based on Status__c
field. So, I am using Query with GROUP BY. However, getting this error
System.SObjectException: Invalid field Status__c for AggregateResult
Code
public static List<AggregateResult> getEverythingUsingGroubBy(){
List<AggregateResult> lstContact = new List<AggregateResult>();
lstContact = [SELECT count(Id) recordCount FROM Partner_Task__c GROUP BY Status__c];
for (AggregateResult ar : lstContact) {
System.debug('Count of tasks are ' + ar.get('Status__c') +'is '+ ar.get('recordCount'));
}
return lstContact;
}