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

Hallo
I want to count number of times a particular field called abholort is repeated and display it in the vf page table.
Apexcode:
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}"  /> 
                     
                 </apex:pageBlockTable>
I am getting an error of Illegal assignment from list to list. Can anybody let me know where am I wrong.

Thanks.

 
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.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_agg_fns.htm

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