Friday, 13 March 2015

analytics:reportChart Embedding Salesforce Charts in Visualforce

Embedding Salesforce Charts in Visualforce


So many updates get added to Salesforce.com all of the time that I'll quite often find a new feature that passed me by.

The problem

I was asked to make some improvements to a set of Reports & Dashboards on a customer ORG. Based on the requirements, I knew that I would  have to create Visualforce pages to give me full flexibility over the layout, but I wasn't looking forward to recreating all of the reports.

Today's bonus feature is the Visualforce analytics:reportChart tag that lets you grab the URL or any report that has a chart/graphic in it and then drop that chart into any Visualforce page.

Step 1

Build a normal Salesforce.com report and add a graph to it


Step 2

Grab the ID of the report you just made from the URL

Step 3

Go to your Visualforce page and add the following code
  

  <apex:page> 
                <analytics:reportChart reportId="URL OF YOUR REPORT"/>
            </apex:page>

Step 4

Preview your Visualforce page - you should see the same report Chart appearing in the content. As an additional bonus, the Analytics tag includes a timestamp of the last refresh and is clickable through back to the source report.


Any error messages?

I experienced one error message when setting this up for the first time. As the Visualforce page could potentially be accessed by anyone you need to ensure that the source report is also publically accessible.