You need to sign in to do that
Don't have an account?
Issues attaching PDF to Opportunity
So I have two pages that share the same controller. On the first page you enter you inputs and the second page rendered as a PDF has all of you outputs. Before Spring '09 something like this wouldn't have worked.
It now works fine if you direct a user straight to that page but if you try to get the content of the page and turn it into an attachment it does not work.
Here is the code:
Page 1: pdfCreate
<apex:page controller="pdfIssues">
<apex:form >
<apex:inputText value="{!yourName}"/><br/>
<apex:commandButton value="View PDF" action="{!view}"/>
<apex:commandButton value="Attach PDF" action="{!attach}"/>
</apex:form>
</apex:page>
Page 2: pdfView
<apex:page controller="pdfIssues" renderAs="pdf">
<apex:outputText value="{!yourName}"/><br/>
</apex:page>
Controller:
public class pdfIssues {
public String yourName {get; set;}
public PageReference view() {
PageReference pdf = Page.pdfView;
return pdf;
}
public PageReference attach() {
Id oppID = [select Id from Opportunity limit 1].Id;
PageReference pdf = Page.pdfView;
Blob pdfContent = pdf.getContent();
Attachment doc = new Attachment(
ParentId = oppID,
Body = pdfContent,
Name = yourName +'.pdf',
ContentType = 'application/pdf'
);
insert doc;
return new PageReference('/'+doc.Id);
}
}
If you click the View PDF button everything works great, controller state is maintained and the PDF is rendered successfully. If you clikc the Attach PDF button you will be returned to the attachment but when you try to view it there will be an error.
This is a simplified example but in my more complex page this is some additional strange behavior. It will execute the Attach() method 4 times and insert four PDFs, non of which can be opened.
-Thanks,
Jason
Information I got from support included a stack trace (I now suspect it had nothing to do with your stuff at all) that clearly showed a failure because of binding to a static property.
The fix for the 4 attachment issue was applied to cs0/cs2/na1/na6 last night.
All Answers
I'm not sure what makes you think I am binding to a static property. My example above has no static properties.
Thanks for patching the 4 attachment issue as I don't believe my example above fully reproduced this behavior.
I also just tested the example above on our cs2 sandbox and it works great. Not sure if it's fixed in prod yet but thanks for fixing this so quickly!
Information I got from support included a stack trace (I now suspect it had nothing to do with your stuff at all) that clearly showed a failure because of binding to a static property.
The fix for the 4 attachment issue was applied to cs0/cs2/na1/na6 last night.