I have a requirement to send an email to a few users on click of a button on an object. I created an Email Template with merge fields. Then I created a Visual Flow to retrieve the email of all the users that are assigned to another related object with a specific role. I tried to send the email by creating an Email Alert. When creating the Email alert, I noticed that the recipient user needs to be specified in the Email Alert itself. But this does not work for me as I would need to retrieve the Email address of certain users at run time. I need to send the email using HTML formatting with tables. I also saw Send Email in the Flow palette but that uses only a text template. How can I send a HTML Email Template to a collection of recipients from visual Flow?
1 Answer
First principles of Email Alerts:
- The recipients have to be fields in the target object (or, in some cases, related objects)
- For example, fields of type
Email
, relatedContacts
, relatedUser
fields, the record owner, team members, etc. The allowable fields are shown in the Email Alert dialog that depends on the target object type
So, for Visual Flow, you have some choices:
- Populate the target object (say, custom fields of type Email) with collected email addresses -- then, workflow or process builder can handle the email alerts.. or ...
- Call Apex to do the work by sending outbound email (see invocable methods) .. or ..
- Populate some other custom object
EmailProxy__c
(one record per email recipient) with each collected email and then have workflow/process builder run on that custom object's creation to send the email alert
Or, some combination of the above
Most likely, if you want HTML table formatting, you will need a VF Email Template and possibly a custom component with its own controller.
-
Thank You. I opted to populate the target object with the email addresses.– NeemaCommented Sep 16, 2016 at 17:10
-
Thanks for this response @cropredy - I am trying to solve a similar use case where an HTML Email record is inserted upon another object's Workflow Rule's criteria being met. Would I still need to invoke Apex code for this (is this code I would have to write) or does this exist a class in the SF instance already?– GPPCommented Aug 22, 2017 at 18:23