4

I have three Salesforce reports and two Visualforce pages that render as PDF pages. I'd like to print all of them with one button press. In case it matters, the reports and Visualforce pages are parameterized. The content of the report is based on which site (custom object) it is being run for.

These are sufficiently important that we'd consider creating custom VF pages of the three standard reports if there was a way to print just VF/PDF pages in a batch.

2 Answers 2

2

A really interesting question!

I guess the answer depends on how similar the pages are. Do they use same standardController (or maybe only a custom controller?), will same parameter(s) be passed to them? Or would you have to modify the params because one needs id pointing to Account and another to Opportunity?

Assuming all pages need same param(s): /apex/pageName?id={!Opportunity.Id} and all use Oppty std. controller - you could merge them all in one master page with <apex:include>:

<apex:page standardController="Opportunity" readonly="true" renderAs="pdf">
    <apex:include pageName="page1" />
    <apex:include pageName="page2" />
    <apex:include pageName="{!$Page.page3}" /><!-- compile-time references are a good thing, they protect you when you try to delete the referenced page by mistake -->
</apex:page>

This tag doesn't allow passing parameters so I think you'd have to pass everything you need in the URL of the main page. You could also try without the same stdController but I think pages will start to complain about fields fetched without being queried for so you'd have to modify your constructors.

If you'll have parameter clashes (or you'll have more time on your hands) you could rename them or consider reworking these 3 pages into VF components. Components are even better than "include" because you can pass attributes to them (imagine extending of existing library of VF tags with your own). You could still have the original pages left, serving as thin wrappers over the newly created components.


As for grabbing the reports - I encourage you to try out the Analytics API, there also are some questions posted over here.

Long ago I've created an abomination of a component that's pretty much screenscraping the report page: Scheduled reports as attachment. Maybe you'll be able to reuse something from it (it doesn't allow param passing, only the report's Id; would be easy to extend though or remove the check).

But if you have time - at least try to do it the proper way and consider sharing with us ;) It's now my most upvoted answer... not sure if I should be proud but clearly there was huge demand for something like this!

P.S. VF page size is capped at 15 MB if I recall correctly...

2
  • I've tested this technique on the two reports pages that are already Visualforce pages that render as PDFs. Works great! The reports are all on contacts, but two of them are on contacts and related contacts. The two pages I'm using now have controller extensions, both of which I've included in the main page. Note: I've removed renderAs="pdf" from the main page as both included pages have it already. Seems to work fine that way.
    – Jagular
    Commented May 5, 2014 at 14:55
  • Great news :) Good to know, I just thought it should work, haven't used it myself to date. But Use debug log / developer console to check whether extension's constructor runs once or more than once - you have a chance of running out of SOQL there so you might still consider moving some queries from constructors to getters for example...
    – eyescream
    Commented May 5, 2014 at 20:04
1

Cloud 4 J handles this very well. http://www.cloud4j.com/report-builder.html

They now provide the ability to add multiple reports to a single process and have the output as PDF. We use the report scheduler product and find it saves a tremendous amount of time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .