You need to sign in to do that
Don't have an account?
Shravya 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:
Thanks.
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.
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.