0

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.

Issue

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.

<apex:form>

 function myClose(){

    self.close();
    window.opener.location.href="/{!$CurrentPage.parameters.Id}";

    //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:pageBlockButtons>
      <apex:pageMessages />

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

    </apex:pageBlock> 
  </apex:form>

Class

public void savePdf() {

    PageReference pdf = Page.GenerateQuotePDF;
    pdf.getParameters().put('id',parentId);
     pdf.setRedirect(true);
    // 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; 

  }   
3
  • 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

0

Browse other questions tagged .