0

I need to generate a document for any given account that lists a detailed view of their contacts, opportunities, activity etc. My first instinct is to simply use renderAs on a custom visualforce page that contains all the account info I need. However, I'm realizing that I would need to generate such a page for each opportunity connected to the account (and possibly each contact though I might get by with a related list there). Is there a way to generate a page for each item that would appear in a related list so we could see (for example) the description of an opportunity that would be too long for a related list column?

Secondarily, if they do end up being separate pages, how would you recommend turning them into a single document with as little effort on the part of the user as possible?

2

You'll probably want to use a combination of pages and components. Each top-level page uses renderAs to make the PDF files, but uses components so you can have the same look-and-feel across the various types. For example, you might declare three components: pdfAccount, pdfContact, and pdfOpportunity. Then, depending on the page, you'll simply render the pages as you like.

AccountPDF

<apex:page standardController="Account" renderAs="PDF">
    <c:pdfAccount account="{!Account}" />
    <apex:repeat var="accountContact" value="{!Account.Contacts}">
        <c:pdfContact contact="{!accountContact}" />
    </apex:repeat>
    <!-- and opportunity code here... -->
</apex:page>

As far as making it easy for the user: just create a Custom Button or Link, using the Visualforce pages you just created. The user clicks it, and the PDF will be generated for them to view or print.

Also, if each record should be its own page, just set up a div with the page-break-before attribute in each component:

<apex:component>
    <div style="page-break-before: always"></div>
    <!-- rest of code here -->

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.