function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aaron WallaceAaron Wallace 

Apex:outputfield not outputting anything on VisualForce Page


I am trying to create a pdf from the Lead Object in Salesforce using the Apex language. I am able to create the pdf and attach it to the Current Lead but it does not pull in any of the information from the Lead into the PDF itself.
Page Code:

<apex:page standardController="Lead" renderAs="pdf" showHeader="false"> 
    <apex:stylesheet value="{!$Resource.pdfCss}"/> 
    <apex:panelGrid columns="1" width="100%"> 
      <apex:outputField value="{!Lead.Name}" styleClass="companyName"/> 
      <apex:outputText value="{!NOW()}"></apex:outputText> 
    </apex:panelGrid> 
</apex:page>

Class Code:

public class attachPDFToLead { 
    private final Lead a;
    public attachPDFToLead(ApexPages.StandardController standardPageController) 
       { 
          a = (Lead)standardPageController.getRecord(); 
       } 

public PageReference attachPDF() {
    PageReference pdfPage = Page.PDF; Blob pdfBlob = pdfPage.getContent(); 
    Attachment attach = new Attachment(parentId = a.Id, Name = 'insuranceVerification.pdf', body = pdfBlob); 
    insert attach; 
    PageReference pageURL = new ApexPages.StandardController(a).view(); 
    pageURL.setRedirect(true); return pageURL; 
} 
}
PavanKPavanK
Hi,

How you are calling this page, you are passing parameter of lead id?
Aaron WallaceAaron Wallace
It is feed by a custom button. Sorry for leaving that out.

User-added image
Aaron WallaceAaron Wallace
I am not sure if i am passing the variable to be honest. I was a little confused on where to pass it in at. I got alot of this from a tutorial and branched into making it perform the way i needed it to.
VineetKumarVineetKumar
Even the value for NOW is not available on the pdf?
Aaron WallaceAaron Wallace
The Now value does export correctly.
VineetKumarVineetKumar
Just try opening the page as /apex/pageName, rendering as pdf, and try debugging the error if any on your page.
Aaron WallaceAaron Wallace
I'm not receiving any errors.

I'm not receiving any errors.
Aaron WallaceAaron Wallace
I can use the code below and it spits it out fine. Just not any of the lead information.
 
{!$User.FirstName} {!$User.LastName}