What is the correct way to declare and reference a report data table (in Visualforce)?

The report is filtered by account, and I want it to be visible when rendered as "pdf".

I'm writing a controller extension to get tasks and events from a contact (the standard controller = Account). This part works. Now I'm trying to create a data table so I can access report information when I render the report as a pdf.

I used the documentation around "Get Report Data" from the SF developer website, but I'm not sure how to declare it so I can use it in my visualforce page.

I've tried using

Public transient Reports.ReportResults reportResults;

in the controller, and then

<apex:pageBlockTable value="{!reportResults.factMap['T!T']}" var="Report">

in the VF Page, but it gives me a syntax error. Found 'reportresults.FactMap'.

This is my first attempt at this, so I'm not sure what I'm missing. Is there perhaps a better way to reference a report table that is visible in a pdf rendered VF page?

Thank you


You have two basic problems.

First, you need to use { get; set; } in order to access anything via merge fields.

Second, you can't generally use these types of objects in merge fields, because there are methods involved. Instead, you'll need a "wrapper class" to hold the data, which you'll then expose on the page.

public class ReportData {
    public Decimal grandTotal { get; set; }
    // ... other properties here ... //
public ReportData data { get; set; }
void buildReportData() {
    data = new ReportData();
    Reports.ReportResults results = getReportResults();
    data.grandTotal = (Decimal)results.getFactMap().get('T!T');
    // ... more logic here ... //
  • Thank you! I'll implement this today and let you know how I get on :) – Janet C Nov 25 '19 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.