How to send table in emails via flow?

Hi! 😀

In this article, I’m gonna share something very cool which was not possible to do declaratively before Spring ’21.
With Spring ’21 Salesforce introduced a feature that now allows us to send Rich Text Emails via flows. And with the help of this amazing feature, I’ll show you how we can embed table(s) containing related records data in our emails.

For some context, let’s take a simple use case.

Use case

We want to send a list of open cases, in tabular format, related to an Account to the Account owner.

Let’s Roll

For reference, this is how the final flow should look like:

Step 1: Create a variable, parentAccount as follows.

Step 2: Get all the open child cases using Get Records element.

Step 3: Create a variable, table as follows:

Step 4: Create a variable, tableColumns as follows:

<tr>
 <th style="border: 1px solid black;">CaseNumber</th>
 <th style="border: 1px solid black;">Subject</th>
 <th style="border: 1px solid black;">Status</th>
 <th style="border: 1px solid black;">Priority</th>
</tr>

Step 5: Use an Assignment element to ‘add’ tableColumns to table variable.

Step 6: Add a Loop element to iterate over all the open child cases.

Step 7: Create a formula, tableRow as follows:

'<tr><td style="border: 1px solid black;">' + {!OpenChildCase.CaseNumber} + 
'</th><td style="border: 1px solid black;">' + {!OpenChildCase.Subject} + 
'</th><td style="border: 1px solid black;">' + TEXT({!OpenChildCase.Status}) + 
'</th><td style="border: 1px solid black;">' + TEXT({!OpenChildCase.Priority}) + 
'</th></tr>'

Step 8: Use an Assignment element to ‘add’ tableRow to table variable.

Step 9: Use an Assignment element to ‘add’ ” </table>” to table variable.

Step 10: Create a Text Template variable, emailBody as follows:

Step 11: Send the email using Send Email action as follows.

And we’re all set.

How it’d look like?

To save you some work, I packaged the flow which you can install from here: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6F000001ZLuu

What more can you do?

  • You can get as fancy as you want by adding inline styling(CSS) to the table header and rows.
  • You can also use subflows to make it reusable to some extent.

I hope you find this useful! I’ll catch you in the next one! ✌
Thank you for being an awesome reader! Subscribe to ForcePanda to receive all the latest updates straight to your inbox.

24 thoughts on “How to send table in emails via flow?

  1. This is awesome! Thank you for this! How would we make each case within the table in the email clickable for the recipient to navigate to?

    Like

  2. Pingback: Send Emails with Tables in Flow – NPSP Example with Payments – Sunshine and Other Unhandled Exceptions

  3. Pingback: Track Field History on User Object Using Before-Save Flow – The SFDC Post

  4. I would like to add images to the table.

    However, I don’t want the images to be showing up as links. The field on Salesforce is a url field.

    They should be embedded within the table so that they are visible on the email. The field on Salesforce is a url field. How can I embed images into the table using the url fields?

    Like

  5. Pingback: Send Tables in Email in Flow – NPSP Example #2 Memorial Gifts – Sunshine and Other Unhandled Exceptions

  6. Hi ForcePanda,

    Thank you for the excellent tutorial – very helpful for practicing Flows and improving my understanding.

    For getting records, should we store all records? Otherwise, “OpenChildCases” does not show up as a potential record collection variable in the “OpenChildCase” loop. I bring this up only because “Only the first record” is the default option for Get Records.

    Thanks for your help!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.