I am opening a pop up VF page as 'render as pdf'.I have created a button Save and on click on save i am closing the pop window and saving PDf to opportunity.


When i am saving the code when calling the savePdf method without rerender and oncomplete.Its saving the attachment and i am able to open the attachment in opportunity without issue.When i am using either using rerender or oncomplete i am able to save the attachment but it says ".'Failed to load document'"

Its been a week i am stuck please help.


 function myClose(){


    //you could also use self.close();    
 <apex:pageBlock mode="maindetail" id="thePb">  

      <apex:pageBlockButtons >
        <apex:commandButton value="Save to Opportunity" action="{!savePdf}" oncomplete="myClose();"  />

      <apex:pageMessages />

     <iframe height="600px" id="Page" name="InvoicePDF" src="/apex/GenerateQuotePDF?id={!parentId}" width="100%"></iframe>



public void savePdf() {

    PageReference pdf = Page.GenerateQuotePDF;
    // create the new attachment
  Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

        body = pdf.getContent();

    attach.Body = body;
    // add the user entered name
    attach.Name = 'Opportunity'+ '.pdf';  
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = parentId;
    attach.ContentType = 'application/pdf';
    insert attach; 

  • Where is the 'Failed to load document' message coming from? Is it the Javascript in the myClose() function? Or is it a Visualforce error message? Jun 16, 2014 at 0:21
  • This looks a lot like your previous question PDF unable to load..when using oncomplete or rerender Jun 16, 2014 at 1:27
  • The error is coming when trying to open the attachment from related list of opportunity.When i click on view it says failed to load document
    – miku
    Jun 16, 2014 at 2:49


Browse other questions tagged .