You need to sign in to do that
Don't have an account?
Lynn M Grande
Attaching file in VF controller leads to multiple attachments
I have a VF page rendering as a pdf and have added an action calling a method in controller to attach the pdf to the record.
When it runs, it attaches 5 times. How can i generate a pdf to allow for preview and have it attach only once to record?
If I put buttons on page to accomplish the attachment, I believe the pdf will show the buttons.
Any suggestions????
Thank you!!
When it runs, it attaches 5 times. How can i generate a pdf to allow for preview and have it attach only once to record?
If I put buttons on page to accomplish the attachment, I believe the pdf will show the buttons.
Any suggestions????
Thank you!!
Is it possible that you post your current code here, so we can help you better?
Thanks in advance!
Best regards,
Martijn Schwärzer
This is the line in the VF page......
<apex:page standardController="Case" extensions="myrExtension" action="{!savePdf}" renderAs="PDF" showHeader="false">
This is the method in controller:
public void savePdf() {
PageReference pdf = Page.XXXPDF;
// add parent id to the parameters for standardcontroller
pdf.getParameters().put('id',parentId);
// create the new attachment
Attachment attach = new Attachment();
// the contents of the attachment from the pdf
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
attach.Body = body;
// add the user entered name
attach.Name = 'xxx.pdf';
attach.IsPrivate = false;
// attach the pdf to the account
attach.ParentId = parentId;
insert attach;
// send the user to the account to view results
return;
}