Previously I had written same blog post and it was working fine before Winter 16. However, after Winter 16 critical update was released by Salesforce to consider getContent() method as a callout. If this update is enabled in your Salesforce instance then my previous blog post will not work.
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.
Again, consider below simple Visualforce page, which we want to send as an attachment.
Objects are objects, even if they are standard or custom objects. Salesforce simplified navigation to access Objects, we can access it now from “Object Manager” menu in setup.
2. Lightning App builder to edit record page layout (pilot)
“Lightning App builder” should be enabled first to use this feature. We can use lightning components developed in Org or from AppExchange and change new lightning layout by using intuitive, drag and drop page layout editor.
3. Rollup Summary field limit increased from 10 to 25
4. Restricted Picklist (Pilot)
Using Apex , Dataloader or any other API , it is possible to save any other value than allowed value in picklist field. This future will enforce data integrity and result in error if other than allowed value selected in DML operation.
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 use returned blob data as a attachment in Email.
Update – 21 Oct 2015 (Winter 16)
After Winter 16 release, this solution will not work as getContent() method is treated as callout and if we try to call it from Async Apex or Rest API in this case, it will not return pdf content.
This solution will only work for you if you have not enabled critical update “PageReference getContent() and getContentAsPDF() Methods Treated as Callouts” in your Salesforce organization.
If we are talking about achieving same in Trigger then it would be problem. Trigger does not support getContent() method of PageReference class. If you are thinking to use getContent() in future call then again we are not lucky, because @future methods does not support it. Also Apex job doesn’t support this method.
Now, I hope you understood that in which situation we are 🙂
So, In this article, I am going to explain how to resolve this issue. Not exactly resolve but workaround for above problem.
Solution is very simple, We will expose apex method as a REST API. Code for sending email will be written in APEX based REST API and our Trigger will call this method asynchronously using @future annotation.