3

I created a salesforce report from "Reports & Dashboards" but I like to customize so that:

  1. I can change the label and color of columns
  2. Embed into an apex page so that I can use renderas='pdf' to export to pdf.

I know 1 can be achieved by using analytics API but that API can't be used for generating pdf since it can be only accessible through restful API. Is there any way so that I can still use salesforce report to generate custom report on PDF or I need to create custom apex page with custom query?

2

You can fetch the whole page with the report in Apex using the REST calls (requires creation of remote site) or with getContent/getContentAsPdf call from the PageReference class. See screen scrape Salesforce with REST GET call from Apex for a sample.

Once you have the payload, you can show it on your VF page (I think an <apex:outputText ... escape="false"> will be needed) and there you can apply CSS you want.

Try to mix & match these flavours (use a report id that works for you)

/{!reportId}?isdtp=vw // should strip out the top of the page
/{!reportId}?export=1&xf=csv&enc=UTF-8 // export as csv
/{!reportId}?excel=1&details=yes // "printable view"

You could also have a look at Scheduled reports as attachment to nick the code that tries to cut the unimportant stuff and get only the <table> with the actual data.

Its fragile, it's a hack, I look forward to the day the Analytics API will work for more than 2K records... but it's something.

0

The only way (IIRC) to add a report to a VF page is through an iFrame. As such, I do not believe it will render when the VF page is output as a PDF. Your best bet would be to recreate the report using APEX/VF OR, you could train your users on how to access and download the report as needed.

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.