Apex:输出字段在VisualForce Page

时间:2016-07-26 22:00:31

标签: apex-code

我正在尝试使用Apex语言从Salesforce中的Lead对象创建pdf。我可以创建pdf并将其附加到Current Lead,但它不会将Lead中的任何信息提取到PDF本身。

页码:

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

班级代码:

public class attachPDFToLead {

private final Lead a; //Lead object

//constructor
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;
}

}

按钮设置:

Button Setup

0 个答案:

没有答案