You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Email existing Visualforce PDF
Hello All,
I have a VF page that renders record information as shows it as a PDF . I am using renderAs="PDF"
How can I now email that PDF?
I thought I needed an email controller show below
RequestPDF is the name of the VF PDF page that is rendering the data. How do I pass the id to the controller? I would like to try with either a button or maybe when a user updates and saves the record. Either way the id and email address is sent to the controller. And if the email address is null prompt for 1?
Thank you,
P
I have a VF page that renders record information as shows it as a PDF . I am using renderAs="PDF"
How can I now email that PDF?
I thought I needed an email controller show below
RequestPDF is the name of the VF PDF page that is rendering the data. How do I pass the id to the controller? I would like to try with either a button or maybe when a user updates and saves the record. Either way the id and email address is sent to the controller. And if the email address is null prompt for 1?
public with sharing class RequestPDF_EmailController { @RemoteAction public static string SendAttachment(String sEmailAddress, String tempId){ String sMessage=''; try{ Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage(); Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); PageReference pref = page.RequestPDF; pref.getParameters().put('id',tempId); pref.setRedirect(true); Blob b = pref.getContent(); attach.setFileName('AttachedInV.pdf'); attach.setBody(b); semail.setSubject('Inv Details'); semail.setToAddresses(new List<String>{sEmailAddress}); semail.setPlainTextBody('Please find the attached INV details'); semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach}); Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail}); sMessage='SUCCESS'; } catch(Exception ex){ sMessage=ex.getMessage()+'\n'+ex.getLineNumber()+'\n'+ex.getCause(); } return sMessage; } }
Thank you,
P
As mentioned in the above link "Visualforce includes a bunch of javascript stub methods and helpers based on the controllers used that have @RemoteAction methods in them. Custom buttons lack the intelligence to do this and I believe @RemoteAction calls are not possible in this way from buttons.
That at least would be the official answer, if you were willing to reverse engineer how @RemoteAction methods actually pass data back to the server it may be possible to make an unsupported implementation."
All Answers
>> https://developer.salesforce.com/blogs/developer-relations/2008/06/emailing-visual.html
There is an implementation in the above link that has a description of the implementation of how it can be done can you try checking it out.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
I think I have all this I just need to be able to send it. Can I initiate the send via a button or based on a field update?
Thanks
P
As mentioned in the above link "Visualforce includes a bunch of javascript stub methods and helpers based on the controllers used that have @RemoteAction methods in them. Custom buttons lack the intelligence to do this and I believe @RemoteAction calls are not possible in this way from buttons.
That at least would be the official answer, if you were willing to reverse engineer how @RemoteAction methods actually pass data back to the server it may be possible to make an unsupported implementation."
P