Friday 23 November 2012

Sending Document as an attachment in the form of Pdf Using Workflow Rules of force.com platform and Visualforce Template feature


Emailing the pdf on click of a boolean check box or click of a button are frequent requirements for which we often think of using Triggers and using Outbound Emails of apex .

This requirement can be easily accomplished through workflow rules and the Visualforce Email Templates

In this blog POST will walk through on how to approach this

Step 1:
Creation of Email Field This is the first step to create an Email Field so that when we develop workflow rules when for the email alert the Recipient Type is asked we may fill in the email field
Step 2:
Creation of workflowThis is a simple step where based on business criteria draft a workflow rule.Usually rule should be to trigger the email alert only if the boolean flag is checked .
Step 3:Creation of email template The email Template will be a visualforce template and hence if you are familiar with visualforce this must be a straight forward impementation
Below is the sample code that you may customize by replacing with your relevant object name



   
   Please find your  receipt attached with this mail.
   


 


  
    



<!-- Section to insert header-

{!$Label.Header}

Label1 Label 2 Label 3

Image From Notes and Attachment


If have any image to display from documents then you will have to use the following
https://AAA.salesforce.com/servlet/servlet. ImageServer?id=BBB&oid=CCC AAA = your SFDC server, found in the URL of any SFDC link after you log in BBB = the record ID of your publicly available document CCC = your organization ID You can pull from documents.Dont pull from static Resource .It never works .
I answered couple of questions in stackexchange recently and this promoted me to write this blog post so that may help .

http://salesforce.stackexchange.com/questions/4637/is-it-possible-to-have-html-in-a-visual-force-email-template/4639#4639

http://salesforce.stackexchange.com/questions/4641/is-is-possible-to-display-an-image-or-icon-in-a-email-using-a-visualforce-templa/4643#4643

6 comments:

  1. From Visual-Force template. I have to send Attachment stored under Notes & Attachments

    Please let me know if you find a way to attach files from "Notes and Attachment" with Visual-force template. approval like to see all the attachment(2-3 generally) supporting approval request. Let me know how is it possible to attach them from

    Notes and Attachment

    ReplyDelete
    Replies
    1. https://sites.secure.force.com/appexchange/ideaView?id=08730000000BrbWAAS

      This is currently under ideas in sfdc and one way you can still go on implementing is using outbound email service .Here methods are available that you can attach the attachment

      http://blog.jeffdouglas.com/2010/07/22/create-and-email-a-document-with-salesforce-com/

      This is helpful.You can query all attachments and then use as an outbound email.

      Thanks let me know any more help you need!

      Delete
    2. Thanks for the detail Mohit, from visual-force email template we have to send notes and attachment. E-mail template is part of approval process and with approval request,director would like to see all the attachment user has inserted in custom sales-form. From visual-force email template, not sure how this can be done. From template I can query attachment and attach all of them in a single html document but that's not pretty(require salesforce login) to view them. or can provide the link. Does custom controller (which will call apex class) from template can attach all the notesandattachment section

      Delete
  2. Hi Mohit, thanks for this useful article. What I would like to know is how can I get the email body to be editable once pulled from a VF email template? Would appreciate any thoughts.

    ReplyDelete
  3. To add on, I would like to edit the email body before the email is sent out. Currently, the email body is uneditable once retrieved from the VF email template.

    ReplyDelete
  4. I happened to come across this website PDFfiller http://goo.gl/kYfOYt when I was looking for a perfect way to edit PDF files. I would really recommend this, no software to download and install. You can fill the text fields, add a variety of checkmarks, digitally sign the form and even add pictures. After your pdf form is completed, it can be printed, emailed, faxed or saved on your computer. You can even send fillable pdf forms to your customers, employees, vendors and partners. Also you can find the right fillable form anytime using the form search engine that contains more than 10 Million forms.

    ReplyDelete

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...