The Salesforce analytics API allows reports to be executed and the contents retrieved from Apex code. Using this technique in a Visualforce controller decouples the dataset, allowing an administrator to change the report filter criteria, altering the data that will be displayed in the Visualforce page, without having to change any controller code.
In this recipe, we will create a Salesforce report that displays account names and their associated contact names. We will then execute this report from a Visualforce controller, parse the results, and display these in a Visualforce page.
This recipe makes use of a custom Salesforce report that must be created before the Visualforce page and its controller:
Click on the Reports tab.
Click on the New Report.. button.
Click on the plus icon to expand the Accounts and Contacts folder.
Click on Contacts and Accounts in the expanded report type list.
Click the Create button, at the bottom right of the page...