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
DrBixDrBix 

Another Possible bug?

I have functionality in our application that creates three PDF attachments and sets the parentId of the attachments to a custom object.  If I do not mark the Visualforce Pages with a renderAs="PDF" and then do a getContentAsPDF() it would seem that only ONE of the PDFs is correctly created (even though I see three insert statements -- one for each PDF).  HOWEVER, if I DO mark the page as renderAs="PDF" and then just do "getContent ()" all three are created and inserted.  What in the world could be causing this issue?  I'm happy I have a work-around, but not happy about the extra 60 to 90 minutes it took me to find this issue.  Is there some unknown governor limit that restricts the number of calls to getContentAsPDF()?

 

What works (renderAs="PDF"):

  Page.PDF1, getContent ()

  Page.PDF2, getContent ()

  Page.PDF3, getContent ()

 

What does NOT work (no renderAs="PDF" in the Visualforce page)

  Page.PDF1, getContentAsPDF ()

  Page.PDF2, getContentAsPDF ()

  Page.PDF3, getContentAsPDF ()

 

Thanks in advance.

Arish_KhanArish_Khan

define VF Page as

 

<apex:page Controller="YourPageControllerNAme" renderAs="pdf" showHeader="false" contentType="application/pdf">

 

</apex:page>

 

and use the code below to save the page as attachement. Say the parent Id is Opportunity opr, then we can add the attachment to Opportunity as:


        PageReference pdfPage = Page.YourVFPageName;
        pdfPage.getParameters().put('id',opr.id);
        Blob pdfBlob = pdfPage.getContent();
        Attachment a = new Attachment(parentId = opr.id, name='Name of the attachement', body = pdfBlob);
        insert a;

 

 

 

----------------------------------------------------------

Mark it as solved if it answers your issue.

DrBixDrBix

That is what I did to make it work.  However, my desire is to make the pages "Multi-purpose."  That is, viewable as either a standard Visualforce Page OR PDF.  The Apex code is what fetches the content as PDF (ex:  getContentAsPDF ()).