Getting Started with Salesforce Quick Action APIs – Part 4 (Email Action with email template)

This is in continuation of previous posts on Salesforce Action APIs. For previous posts refer to this link Getting Started with Quick Action APIs

This Quick Action APIs – Part 4 where we will focus on how to set an email action with Email Template so that the expected email the body can be automatically generated based on a pre-defined email template.

Pre-requisites for this exercise:

  • Create an HTML email template (with or without letterhead) named "Quote Dealer Email Template" or any other type based on your choice.

For this, we have to build a scenario where we are using the visualforce page to generate PDF and the same PDF needs to be sent out to the customer using a pre-defined email template using "Send Email" Quick Action.

Steps will be the following:
  • Create a simple visualforce page using the standard controller of "Quote" object named "QuotePDF"
  • Embed the "QuotePDF" in lightning Component using an iframe for preview.
  • Upon iframe, Load saves the PDF under the current Quote record as Content Document and return content document id.
  • Now pass this Content Document ID array under the "ContentDocumentIds" attribute of setActionFieldValues funtion of Quick Action APIs.
  • Then query the required email template named "Quote Dealer Email Template" using the apex class method "getQuoteEmailTemplate".
Here is a catch, as per Salesforce Document the field used for setting an email template is "EmailTenplateId" but if you set the email template record id directly to this variable of Quick Action API function it will not work.

So what we need to do:
  • Instead of using "EmailTemplateId" as an attribute to set email template Id used "EmailTemplate" attribute and set JSON object with values as template id.
Note: For Quick Action APIs to work the requested component should be present on the record current screen from where this action will invoke else system will through error ☹️


The key points to consider:

  • EmailTemplateId: Instead of using "EmailTemplateId" use "EmailTemplate" with a JSON object with value attribute as template record Id.

Comments

Popular posts from this blog

Getting Started with Salesforce Quick Action APIs – Part 2 (Automatically populate fields with custom data values)

Getting Started with Salesforce Quick Action APIs – Part 1 (Invoke using custom button)