I wanted to display records from an aggregate query on my visualforce page. I expected this to be pretty straight forward but it turns out there are many ways to get this done and most solutions on the forums were not as straight forward as I expected.
I was storing my results in a list of AggregateResult sobjects. Following is the code of my controller extension.
Controller Method:
public List<AggregateResult> resultValue() {
AggregateResult[] results = [SELECT Name, Count(Id) Quantity FROM Opportunity GROUP BY Name];
return results;
}
Visualforce Page:
<apex:page controller="TestController">
<apex:form >
<apex:repeat value="{!results}" var="result">
{!result.Name}: {!result.Quantity}
</apex:repeat>
</apex:form>
</apex:page>
No comments :
Post a Comment