function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shravya Rama 9Shravya Rama 9 

Group by in SOQL Query

I want to count number of times a particular field called abholort is repeated and display it in the vf page table.
public List<String> ShowSuggestions = new List<String>();

    public List<String> getSuggestions() {
        ShowSuggestions =  [select Abholort__c, COUNT(Name)  from Fahrzeuge__c
                            GROUP BY  Abholort__c ]; 
        return ShowSuggestions;               
VF page
<apex:pageBlockTable value="{!Suggestions}" var="showsugg"   >
                     <apex:column value="{!showsugg.COUNT(Name)}"  />  
                     <apex:column value="{!showsugg.Abholort__c}"  /> 
I am getting an error of Illegal assignment from list to list. Can anybody let me know where am I wrong.


Best Answer chosen by Shravya Rama 9
pranoti patilpranoti patil
Hi Shravya,

You are using aggregate query. Please change ShowSuggestions type to AggregateResult as shown below.

List<AggregateResult> ShowSuggestions =new List<AggregateResult>();

Please find the more info about aggregated function.

kindly mark it as an answer if that resolves your query.