{"id":5662,"date":"2016-08-27T04:53:42","date_gmt":"2016-08-27T04:53:42","guid":{"rendered":"http:\/\/www.jitendrazaa.com\/blog\/?p=5662"},"modified":"2016-08-27T04:55:55","modified_gmt":"2016-08-27T04:55:55","slug":"send-visualforce-as-an-email-attachment-from-apex-trigger-alternate-design","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/send-visualforce-as-an-email-attachment-from-apex-trigger-alternate-design\/","title":{"rendered":"Send Visualforce as an email attachment from Apex Trigger &#8211; Alternate design"},"content":{"rendered":"<p style=\"text-align: justify;\">Previously I had\u00a0written <a href=\"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex\/send-email-with-generated-pdf-as-attachment-from-trigger\/\">same blog post<\/a> and it was working fine before Winter 16. However, after Winter 16 critical update was released by Salesforce to consider\u00a0<em>getContent()\u00a0<\/em>method as a callout. If this update is enabled in your Salesforce instance then my previous blog post will not work.<\/p>\n<p style=\"text-align: justify;\">In this blog post, we will go through alternate design, where we would still be able to send Visualforce page content as an Email attachment. Difference is, instead of Apex Trigger , Invocable Method and Process builder will help us getting there.<\/p>\n<p style=\"text-align: justify;\">Again, consider below simple Visualforce page, which we want to send as an attachment.<\/p>\n<p><!--more--><\/p>\n<p><span style=\"text-decoration: underline;\">PDF_Demo.vfp<\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;apex:page renderAs=&quot;PDF&quot; &gt; \r\n\r\n&lt;h1 &gt;Congratulations &lt;\/h1 &gt;\r\n  This is your new Page \r\n &lt;\/apex:page&gt;\r\n<\/pre>\n<p>Below is Apex class containing Invocable method to be executed\u00a0from Process builder<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/**\r\n * \tAuthor\t\t:\tJitendra Zaa\r\n * \tDate\t\t:\tAug 26 2016\r\n * \tDescription\t:\tMethod in this class is invoked by Process builder to send an Email\r\n * *\/\r\npublic class SendVF_Email_InvocableMethod {\r\n\r\n    @InvocableMethod\r\n    public static void sendEmail(List&lt;Id&gt; lstId){\r\n        List&lt;String&gt; EmailIds = 'ilovenagpur@gmail.com'.split(',');\r\n\r\n        PageReference ref = Page.PDF_DEMO;\r\n        Blob b = ref.getContentAsPDF();\r\n\r\n        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();\r\n\r\n        Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();\r\n        efa1.setFileName('attachment_WORK.pdf');\r\n        efa1.setBody(b);\r\n\r\n        String addresses;\r\n        email.setSubject( 'Check VF From PB' +String.valueOf(DateTime.now()));\r\n        email.setToAddresses( EmailIds  );\r\n        email.setPlainTextBody('Hey there, I am an email Body');\r\n        email.setFileAttachments(new Messaging.EmailFileAttachment&#x5B;] {efa1});\r\n        Messaging.SendEmailResult &#x5B;] r = Messaging.sendEmail(new Messaging.SingleEmailMessage&#x5B;] {email});\r\n    }\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">Last but not the least, we need to create a process builder and invoke above method in same situation, Trigger could have executed it. We can always use some hidden fields in trigger and populate for Process builder so that decision making would be easy.<\/p>\n<p style=\"text-align: justify;\">Don&#8217;t forget to leave your comments and feedback for other possible designs or suggestions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Process Builder &#038; InvocableMethod- Alternative to send Visualforce as an  email attachment from  Apex Trigger <\/p>\n","protected":false},"author":1,"featured_media":5663,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[307,349],"class_list":["post-5662","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","tag-process-builder","tag-winter16"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2016\/08\/Send-Visualforce-as-an-email-attachment-from-Apex-Trigger.jpg?fit=922%2C369&ssl=1","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3851,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/apex\/send-email-with-generated-pdf-as-attachment-from-trigger\/","url_meta":{"origin":5662,"position":0},"title":"Send Email with Generated PDF as attachment from Trigger &#8211; before Winter 16","author":"Jitendra","date":"April 16, 2014","format":false,"excerpt":"There may be scenario in Salesforce that you need to send a Visualforce page rendered as PDF as a part of Email Attachment. This will be very easy if you want to perform this using Controller or Extension class, we just have to call getContentAsPDF() method of PageReference class and\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4870,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/resolve-24-hour-apex-email-limit-error-in-salesforce\/","url_meta":{"origin":5662,"position":1},"title":"Resolve 24 hour Apex email limit error in Salesforce","author":"Jitendra","date":"October 13, 2015","format":false,"excerpt":"How to design and architect Salesforce application so that 24 hour Apex email limit error could be resolved and have reporting capabilities on emails sent from Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Resolve 24 hour Apex email limit error in Salesforce","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/10\/Resolve-24-hour-Apex-email-limit-error-in-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":6880,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/get-current-user-id-in-salesforce\/","url_meta":{"origin":5662,"position":2},"title":"Get Current User Id in Salesforce","author":"Jitendra","date":"February 2, 2019","format":false,"excerpt":"How to get Current Logged in user Id in Apex, Visualforce, Lightning Component and Formula fields in Salesforce","rel":"","context":"In &quot;Lightning&quot;","block_context":{"text":"Lightning","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/lightning\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4102,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-20-lightning-questions\/","url_meta":{"origin":5662,"position":3},"title":"Salesforce interview question related to Lightning framework &#8211; Part 20","author":"Jitendra","date":"February 4, 2015","format":false,"excerpt":"Salesforce interview questions for Salesforce developers and admin , mostly related to newly released Salesforce Lightning components and applications","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3773,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-faq-part-19\/","url_meta":{"origin":5662,"position":4},"title":"Salesforce interview questions &#8211; Part 19","author":"Jitendra","date":"December 16, 2014","format":false,"excerpt":"Salesforce interview questions for developers and admins around Apex, Visualforce, getting Salesforce object name on basis of Id, Apex API limits","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2470,"url":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/salesforce-tutorial-create-simple-ajax-based-visualforce-page\/","url_meta":{"origin":5662,"position":5},"title":"Salesforce Tutorial &#8211; Create Simple Ajax based Visualforce page","author":"Jitendra","date":"October 17, 2011","format":false,"excerpt":"Salesforce Tutorial - Step by step tutorial to create AJAX based application in visualforce page with Apex class","rel":"","context":"In &quot;Web Technology&quot;","block_context":{"text":"Web Technology","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/"},"img":{"alt_text":"Simple AJAX demo in salesforce using visualforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Simple-AJAX-demo-in-salesforce-using-visualforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=5662"}],"version-history":[{"count":2,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5662\/revisions"}],"predecessor-version":[{"id":5667,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/5662\/revisions\/5667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media\/5663"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=5662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=5662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=5662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}