Skip to main content
I followed the steps here (https://www.interactiveties.com/blog/2015/visualforce-button-pdf.php) to render a visualforce page as pdf and then attach it to the record's Notes & Attachments area when I click a custom button. However, when I render this as a standard pdf page in a browser (by connecting the button to the BPAdemo visualforce page) I can see the values populated, but when I attach the same PDF to the record under Notes & Attachment (by connecting the button to attachPDF visualforce page), the values are not populated in PDF. It looks like the outputtext values are not binding to the pdf, how do I get the record's data/values to display? Please help!!! Thank you very much!!!

Here's the code I have for the Apex Class:

public class attachPDFToBPA {

private final BPA__c b; //BPA object

//constructor

public attachPDFToBPA(ApexPages.StandardController standardPageController) {

b = (BPA__c)standardPageController.getRecord(); //instantiate the BPA object for the current record

}

//method called from the Visualforce's action attribute

public PageReference attachPDF() {

//generate and attach the PDF document

PageReference pdfPage = Page.BPAdemo; //create a page reference to the pdfDemo Visualforce page

Blob pdfBlob = pdfPage.getContentAsPDF(); //get the output of the page, as displayed to a user in a browser

Attachment attach = new Attachment(parentId = b.Id, Name = 'pdfAttachment.pdf', body = pdfBlob); //create the attachment object

insert attach; //insert the attachment

//redirect the user

PageReference pageWhereWeWantToGo = new ApexPages.StandardController(b).view(); //we want to redirect the User back to the BPA detail page

pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side

return pageWhereWeWantToGo; //send the User on their way

}

}

These are the Visualforce Pages:

<apex:page standardController="BPA__c">

<h1>Here's a copy of your BPA</h1>

<p>Thank you, <b><apex:outputText value="{!BPA__c.BPA_Signer__r.Name}" escape="false" /></b>,

for joining Our Network!</p>

<p>BPA Signed Date:&nbsp;

<apex:outputText value="{0,date,long}" >

<apex:param value="{!BPA__c.BPA_Signed_Date__c}"/>

</apex:outputText></p>

</apex:page>

<apex:page action="{!attachPDF}" extensions="attachPDFToBPA" standardController="BPA__c">

<!--

Notes:

- Visualforce page for creating a PDF file and attaching to BPA record

-->

<apex:pageMessages ></apex:pageMessages><!-- included for display of errors should they occur -->

<apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so BPA detail information is visible when errors occur -->

</apex:page>

And this is the generated pdf attachment, missing values: 

Outputtext not binding to record when rendering as pdf attachment

 
1 个回答
  1. 2017年11月18日 20:02

    Check the profile permissions (field level security and object CRUD for the BPA__c and BPA_Signer__c objects), and make sure the person viewing the PDF can see those fields.

    If it still doesn't work after you set up the proper permissions, then you might have to create an extension and re-query the BPA__c record to bring in some of those fields to your PDF Visualforce page.

0/9000