function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ivar@MarelIvar@Marel 

Dashboards in visualforce pages

Hi everyone.

 

Has anyone attempted to display a dashboard as part of a visualforce page? I have been browsing around and haven't found anything. The reason I ask is that I want to show one of our dashboards on our company's intranet websites, and figured the easiest way to do it would be to display it in visualforce and publish it as a Site that the intranet web could then incorporate into it's layout.

 

If anyone has any hints or tips I'm all ears :)

 

Regards,

Ivar

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You can pull dashboards in to a visualforce via an iframe, but you will get the headers repeated. Another mechanism is to retrieve the dashboard programmatically (via generating a PageReference for the dashboard and the executing the getContent() method) and simply render the HTML fragment(s) that you are interested in.  

All Answers

bob_buzzardbob_buzzard

You can pull dashboards in to a visualforce via an iframe, but you will get the headers repeated. Another mechanism is to retrieve the dashboard programmatically (via generating a PageReference for the dashboard and the executing the getContent() method) and simply render the HTML fragment(s) that you are interested in.  

This was selected as the best answer
IbigfootIbigfoot

nice tip... i was thinking of visualforce charts..
Ivar@MarelIvar@Marel

Thanks for the help Bob. That got me on the right track. I did a quick proof of concept / test that does exactly what I wanted. Thanks again :)

 

Below is the test's page and controller for anyone thinking about the same:

 

public with sharing class DashboardSnippetController {
	public DashBoardSnippetController(){}
	
	public string getDashboardHtml(){
		PageReference dbPage = new PageReference('https://cs3.salesforce.com/01Z300000007eMK');
		Blob pageBlob = dbPage.getContent();
		return pageBlob.toString();
	}
}

 

<apex:page controller="DashboardSnippetController" showheader="false" sidebar="false">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  <div id="mainArea">
 
  </div>
  <script>
      document.getElementById('mainArea').innerHTML = '{!dashboardHtml}';
  </script>
  <!-- End Default Content REMOVE THIS -->
</apex:page>

 

ASHISH VARMAASHISH VARMA
But i See User-added image. Please suggest to hide this from my visualforce page.
Ivar@MarelIvar@Marel
Hi Shobana. Can you post some details on how you changed the code and how it is failing?
VamsiVamsi
Hi Ivar@Marel,

When I try your above code it throws me an error. Could you please help me.

Error: DashboardSnippetController Compile Error: line 6:104 no viable alternative at character '"' at line 6 column 104

public with sharing class DashboardSnippetController 
{
    public DashBoardSnippetController(){}
    
    public string getDashboardHtml(){
        PageReference dbPage = new PageReference('<a href="https://ap1.salesforce.com/01Z90000000Qy2K');" target="_blank" rel="nofollow">https://ap1.salesforce.com/01Z90000000Qy2K');</a>  // Throwing error on this entire page reference line 
        Blob pageBlob = dbPage.getContent();
        return pageBlob.toString();
    }
}
}
kumar Sanu 8kumar Sanu 8
@ASHISH VARMA

Did you got solution for Problrm ???