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
certi_vimalcerti_vimal 

Visualforce Page as a Dashboard Component

Hi,

 

I have visualforce page showing report data in a page block table. I want to show this page as dashboard component. Is there any way to achieve this easily? I have heard that dashboard component wont get created if you use a Standard Controller, but if you use Controller class or call/refer a page having StandardSetController Class from the concerned vf page, you may have the component available.

 

Could you please advise on this.

 

 

Thanks,

 

Vimal

dwwrightdwwright

Here is a page that I have developed to do this. It's used to display a custom object I created called "Quarterly Report" which is a child object of "Account" and I use it to narrow down my selection to only one Account (I assign the StandardSetController a query that matches Id, so only one record is returned, then I do a get(0) to grab that record)

 

The cool thing is that after this page, I pass my users to another page that does NOT have this controller, so only the landing page for the dashboard has to implement this.

 

 

public class QuarterlyReportController {

	public Quarterly_Report__c QR {get; set;}
	
	
	public QuarterlyReportController  () {
		QR = new Quarterly_Report__c();	
	}
	
	public ApexPages.StandardSetController setCont {get {
		
		if(QR.Parent_Account__c != null) {
			setCont = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, (SELECT Name, Id FROM Quarterly_Reports__r) FROM Account WHERE Id = :QR.Parent_Account__c]));
		}
		return setCont;
	
	} set; }
	
	public List<Quarterly_Report__c> reports { get {
		List<Quarterly_Report__c> reps = new List<Quarterly_Report__c>();
		if(setCont != null) {
			List<Account> accs = (List<Account>)setCont.getRecords();
			reps = accs.get(0).Quarterly_Reports__r;
			return reps;
		}
		else return null;
	} set;}

	public PageReference refresh() {
		return ApexPages.currentPage();
	}
}

 

 

krishnagkrishnag

hi can u post the code for the visualforce page (design) that u have implemented

dwwrightdwwright

Hi,

I'm not sure if you're directing that question to myself or certi_vimal...

 

The code for the VF page corresponding to that extension is here:

 

 

<apex:page controller="QuarterlyReportExtension" showHeader="false" >

	<apex:form >
		Select an Account: <apex:inputField value="{!QR.Parent_Account__c}"/><br/>
		<apex:commandButton value="Get Reports" action="{!refresh}" /><br/><br/>
		<apex:pageBlock >
			<apex:outputText value="No reports defined for this account" rendered="{!reports.size == 0 && QR.Parent_Account__c != null}" />
			<apex:pageBlockTable value="{!reports}" var="report">
				<apex:column >
					<apex:outputLink value="QReportDashboard?id={!report.Id}">Report: {!report.Name}</apex:outputLink>
				</apex:column>
			</apex:pageBlockTable>
		</apex:pageBlock>
	</apex:form>


</apex:page>

 

 

krishnagkrishnag

hi dwwright,

i was asking yours page.thanks for that. I have a small question on this.Is there a possibility so to diplay a dashboard on VF page .in ur page u have a given a link to the report right my requirement is to display the dasgbord on VF page.

dwwrightdwwright

You cannot display a dashboard in a visualforce page. You only have the options of displaying a Visualforce page in one of the slots on a dashboard (Which is what my controller/page above demonstrate)

 

The link in my code directs the user to a second page that displays a record. This all happens inside the little block of space where the visualforce page appears inside the dashboard.

certi_vimalcerti_vimal

Thanks dwwright.

I will ask my developer to look into this and utilise the knowledge that you provided here.

Thanks,

Vimal