I am doing an AggregateResult SOQl query on different picklists on a Contact.
List<AggregateResult> results = [select LeadSource, COUNT(id)cnt from Contact where LeadSource != null group by LeadSource];
Where LeadSource is of type Pick list. This basically gives me the number of records for each value in the LeadSource picklist.
The problem however comes when doing this same type of AggregateResult query for a multi-select picklist. It says I cannot do a group by for a multi-select picklist.
Is there any other way I can do AggregateResult for a multi-select picklist?
Best Answer
https://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_agg_functions_field_types.htm
As per the document link above there is no way to use AggregateResult
However if the no of records are less than 50000 rows you can still loop over the records and use Maps to seggregate and do the count
If you are building something like reporting use @ReadOnly attribute on page so that the no of Rows retrieved is increased .