You need to sign in to do that
Don't have an account?

PDF unable to load..when using oncomplete or rerender..?
have created a VF page and used "render as pdf"
Its working fine when i am using above line without rerender and oncomplete but when i am adding rerender or oncomplete it is not working.I am able to save the PDF in attachment folder but when i am trying to open its showing "Unable to load document"
Even if i remove oncomplete and use Rerender then also its saving the attachment in Attachment object and when i view ,it is not loading and says "Unable to load document"
Javascript Code
Class Code
Please help..
<apex:commandButton value="Save to Opportunity" action="{!savePdf}" />
Its working fine when i am using above line without rerender and oncomplete but when i am adding rerender or oncomplete it is not working.I am able to save the PDF in attachment folder but when i am trying to open its showing "Unable to load document"
Even if i remove oncomplete and use Rerender then also its saving the attachment in Attachment object and when i view ,it is not loading and says "Unable to load document"
<apex:commandButton value="Save to Opportunity" action="{!savePdf}" oncomplete="myClose();"/>
Javascript Code
function myClose(){ self.close(); window.opener.location.href="/{!$CurrentPage.parameters.Id}"; }
Class Code
public void savePdf() { PageReference pdf = Page.GenerateQuotePDF; pdf.getParameters().put('id',parentId); Attachment attach = new Attachment(); Blob body; body = pdf.getContent(); attach.Body = body; attach.Name = 'Opportunity'+ '.pdf'; attach.IsPrivate = false; attach.ParentId = parentId; attach.ContentType = 'application/pdf'; insert attach; }
Please help..
PageReference pdf = Page.GenerateQuotePDF;
pdf.getParameters().put('id',parentId);
pdf.setRedirect(true);
replace the part of code with this. hope it will work.
thanks.
Thanks for your reply..I tried this but i am facing the same issue..I am able to save the PDF but is is not opening..It says failed to load document.
I have changed like you said..
Any other suggestions..?
public PageReference savePdf() {
PageReference pdf = Page.GenerateQuotePDF;
pdf.getParameters().put('id',parentId);
Attachment attach = new Attachment();
Blob body;
body = pdf.getContent();
attach.Body = body;
attach.Name = 'Opportunity'+ '.pdf';
attach.IsPrivate = false;
attach.ParentId = parentId;
attach.ContentType = 'application/pdf';
insert attach;
pdf.setRedirect(true);
return pdf;
}
Thanks
Tejpal
I juste tested the below code works for me in my org.
VF page :
Apex Class
If this helps,please mark it as best answer to help others :)
Still its not working
Can you suggest some thing else..
What's not working for you coz the same code works for me.
I don't understand why ot would work for me and not for you.
I have reposted this question with some more details..Can you please check this and tell me why i am facing this issue.
https://developer.salesforce.com/forums?id=906F0000000AYV3IAO