Send a dynamic email to user-defined contacts with flow

Send a Dynamic Email to User-Defined Contacts Using Flow | Automate This!

By

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Michael Barnes uses Flow to send emails to a dynamically created list of email addresses.


Business need

I need to send an email to recipients flagged by my account manager. However, not every contact on the account needs to be copied on every automated email, and I want to avoid creating an unknown number of contact relationship fields on my Account object. There’s also a limit of 40 lookup relationships per object, so that idea is also not scalable. I may also need to include members of my account team, but perhaps my object does not have a master-detail relationship to the Account object, so classic Email Alerts will not be able to pick up Account Team members for my use case.

The solution

I’ll use Flow to dynamically build a recipient list and let Flow send my email!

Create a mechanism to flag who receives an email using a custom field on the Contact object

I wanted to give my users direct control over who will receive a particular email that is sent by my automation. So, I created a custom checkbox field on the Contact object to allow my end users to flag users who are eligible to receive a certain email type.

Create a flow to build the recipient list and send the email

Next, I needed to create automation to build the recipient list and send the email. I created a flow to do the job. The flow first gets each of the contacts that are flagged using the checkbox field for an Account and then adds them to a list using the new Transform element. After that, the flow gets all Account Team members and uses a Loop to pull the email address associated with each user in the Account Team to an email collection. Finally, the flow uses the Simple Email send action to send a customized message to this collection of email addresses.

Here’s the completed flow. Refer to the breakdowns below for details on each element used.

Completed flow.

Flow breakdown: Part 1

Flow — Part 1: Start, Search for Contacts, and Decision confirming Contacts where found.]

Determine your flow type based on how you want this to behave

For demo purposes, we’re going to use a screen flow. It could be an autolaunched flow if you want to call this from a button and have the email sent automatically; or, it could be a record-triggered flow if you want an update to a record to trigger the email send automatically.

Use a Get Records element to retrieve the contacts of the associated account (#1 in image above)

Because I set a custom field on my Contact object, my users now have control over which contacts will be in the recipient list of the automated email send. My Get Records (Get Contacts on Account) element pulls only those contacts flagged by my users.

Use a Decision element as best practice to ensure you have records in your collection (#2 in image above)

When doing a Get Records element where you need to work with the output, it’s usually a good idea to add a Decision element to confirm you found records. If you don’t, you may get a flow error if you try to work with the retrieved records, and the record variable is null.

Flow breakdown: Part 2

Flow — Part 2: Transform element to add Contact Emails to List, Get Account Team, and Add Account Team to List.

Pull data from one list to another using the Transform element (#3 in image above)

The Transform element is relatively new to Flow and is a handy shortcut for pulling data from a list of records and adding it to another collection element. In this case, I pulled the email addresses for my list of contacts and added them to a Text collection variable in one step using the Transform element where I mapped the email field from the object to the collection variable, rather than using Loop and Assignment elements.

Use Loops to add items from one list to another (#4 in image above)

As an alternative, you can use the Loop element to cycle through each contact in the list and use an Assignment element to add each contact’s email to a list that way. It works just as well, and for my next step, I did just that! I looped through the Account Team member records to pull the related user’s email address and added it to the Text collection variable using an Assignment element. The reason the Transform element does not work here is that the user email is not in the collection variable directly—it’s available through the parent user relationship. At this time, the Transform element can only see fields that are on the primary record.

The reason I do not need a Decision element after using the Get Records element for my Account Team members is that if no records are found, the Loop element will automatically bypass the “For Each” path and go directly to “After Last”, which in this case will do nothing with the retrieved records variable. You can still do a Decision to be safe, but in this case it’s not necessary.

Flow breakdown: Part 3

Send Email Action completes process and sends email.

Use the Simple Email action to send emails from Flow (#5 in image above)

The Simple Email action in Flow is a great out-of-the-box send email feature. At its most basic, you just need to supply a Subject, Body, and Email Address(es) to send out a quick email directly from Flow.

The Body can be built using a WYSIWYG (what you see is what you get) editor, so you don’t need an email template to build a dynamic email. Email addresses can be populated from a Text collection variable populated with a list of email addresses. This allows the send to be dynamic, as designed here, and eliminates the restrictions you encounter when sending a classic email alert. Another limitation of classic email alerts is the Account Team will only populate properly if the object from which you are sending the email has a master-detail relationship with the Account object. If you only have a lookup relationship, the Account Team may not be available. However, with Flow, you can dynamically access the Account Team using a lookup relationship and get the recipients you need for your email.

Send Email (Simple) action where you set Subject, Body, Recipient List, and Object Relationship.

Here are a few configurable options for the Send Email (Simple) action.

  • Body: Pulls from a Text Template (Rich Text)
  • Recipient Address Collection: Populated in Transform and Loop Assignment elements
  • Related Record ID: Account ID that is passed in to start the flow
  • Rich-Text Formatted Body: Must be true if Text Template used for body is Rich Text
  • Subject: If Text Template is used here, be sure it is Plain Text, if Rich Text HTML tags will appear in Subject line

Note: The subject and body can be built dynamic as well using tags in Text Template, based on information gathered in the flow.

There are more features you can explore with the Simple Email action including using email templates and logging email sends on the records on a contact and record related to your send. Best of luck using this tool to meet your business’s needs for more dynamic email routing!

Results

As you can see, you can use Flow Builder to dynamically send emails to specific recipients based on your business needs. Let me recap the solution.

  • Create a custom checkbox field on the Contact object; users gain control over who will receive automated emails.
  • Build a flow that pulls flagged contacts, adds Account Team members, and uses the Transform and Loop elements to collect email addresses dynamically. Then, leverage the Simple Email action to send personalized emails, overcoming limitations of traditional email alerts.

This solution provides flexibility in email routing and enables more tailored communication, helping businesses streamline their processes efficiently.

Resources

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Boost your study routine with flows and email-to-text gateways

Boost Your Salesforce Certification Study Routine with Flows & Email-to-Text Gateways | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Bradley Condon built the […]

READ MORE
Leverage flows to process inbound emails with documents

Leverage Flows To Process Inbound Emails With Documents | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Ohad Idan vanquishes shared […]

READ MORE
Improve sales funnel velocity with Flow

Improve Sales Funnel Velocity Using Flow | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Becka Dente leverages a simple […]

READ MORE