4

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?

  • How do you imagine your chart would look like with picklist "A;B;C" value? As a separate bar in the bar chart for example, different from existing bars for "A", "B", "C" and "A;B"? You probably could make-do with a text field to which you'd copy the picklist's value (before insert, before update trigger since workflows are bit painful with multiselect picklists)... but I just have trouble imagining a scenario where this requirement would be a good idea to be honest... – eyescream May 5 '14 at 21:32
3

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 .

  • I am building this to display the data in the visualforce chart. – codeinprogress May 5 '14 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.