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
VPdVPd 

VF Page renderAs pdf is blank when saving as an attachment.

Hi All,
I have a lighting action button on lead standard page with action type as visualfroce page. When the button is clicked and visualforce is loaded, I need to generate a PDF with some lead data and save this PDF as an attachment. It is working fine in a dev org with Summar17 release but the same logic and piece of code does not work in a sandbox with Winter18 release and creates a blank PDF in attachment.
Any help would be a great relief to figure out if this is a code issue or an issue with salesforce latest release.

Dummy Code:
<apex:page standardController="Lead" extensions="ProposalController" docType="html-5.0" showHeader="false" sidebar="false" standardStylesheets="false" showQuickActionVfHeader="false">
<apex:slds />
<head><script> window.onload = function() {createProposal();} </script> </head>
<body>
   <apex:form id="t" >
<apex:outputPanel id="outerPanel">
  <apex:outputPanel rendered="{!isAttachmentCreated}">
       <!-- Showing attachment link here -->
</apex:outputpanel>
</apex:outputPanel>
<apex:actionFunction name="createProposal" action="{!generateProp}" rerender="outerPanel" />
</apex:form>
</body>
</apex:page>
Controller
public ProposalController(ApexPages.StandardController stdController){
     leadObj = (Lead)stdController.getRecord();
    isAttachmentCreated = false;

}
public void generateProp(){
   PageReference pdf = Page.GenerateProposal;
  pdf.getParameters().put('id',leadObj.id);
  Blob pdfPageBlob = pagePdf.getContentAsPDF();
  a = new Attachment();
  a.Body = pdfPageBlob;
  a.ParentID = leadObj.id;
  a.Name = 'Test Attachment';
  a.Description = 'TestDescription1';
  insert a;
  isAttachmentCreated = true;
}
Page to render as PDF
<apex:page renderAs="pdf" standardController="Lead">Name: {!Lead.name}Source: {!Lead.leadsource></apex:page>
NagendraNagendra (Salesforce Developers) 
Hi,


Do you have any errors in the debug log? I wonder if "getContentAsPdf() doesn't count as a callout and that means you should add your own SF url to Remote Site Settings. Maybe they're tightening the security around that in W'18.

Thanks,
Nagendra