Aggregate functions give a very beautiful meaning to data altogether.
For those of you who knew SQL you obviously know what aggregate functions are and how they beautify your code.
Those who do not know, aggregate functions help you aggregate the date based on certain field.
For example, you want to show the count and Opportunities created on a day, you can aggregate them using SOQL.
So how do we display it on Visualforce:
Just iterate on the AggregateResults and get elements one by one.
A few pointers for debugging:
1. Always use API version 18.0+ while using Aggregate Functions. If you are eclipse, you might want to update it. And frankly if you are still using older version of eclipse, my mind wants to scream and ask you…why?
2. If you are Aggregating using a relationship e.g., Object1__r.object2__c in your SOQL, while fetching from AggregateResults you only need Object2__c, ar.get(‘Object2__c’) I am not really sure why, because I found no documentation supporting this, but it worked for me in the code.