These are examples to illustrate techniques that facilitate using the Send Better Email Action. They include:

Return to Send Better Email

Example: Create a Resource Variable Collection of Strings and Add Individual Email Addresses

Add a collection variable
Populate the collection variable
// for a string
String exampleSingleEmailAddress = "john.smith@example.com";
// or for collections
List<String> exampleStringCollection = new List<String>{"john.smith@example.com","jane.doe@example.com"};
List<Contact> exampleContactCollection = [SELECT Id Contact Limit 2];

Example: configure inputs with sources of email addresses:

The sendBetterEmail package ships with two screen flows that can be used to test and demonstrate the action, ‘Send Better Email Testflow’ and ‘sendBetterEmail Test – Create Test Templates if Needed’. You do not have to activate these flows to use them. Open ‘Send Better Email Testflow’ then select “Debug” (or “Run”).

Flow Examples in Send Better Email Testflow (Send_Better_Email_Testflow)

Flow Examples illustrate different ways of using this Action while providing the ability to test this action in your org. The test flow Send Better Email Testflow(Send_Better_Email_Testflow) not only provides a framework for testing in your org, but also shows some of the common usage patterns including:

  1. Flow resources setup and types of resources used in the Action
  2. Flow process paths that illustrate how setup prior to the action may occur
  3. The Action and parameters in different usage situations

Some of these examples may require prior setup of records. Where necessary, this is described in each of the selected examples. Examples/Tests include:

  1. Flow Example 1 – Simple Email Text – with To, Sender, Reply-To, Subject, Body (All text)
  2. Flow Example 2 – Simple Email with Address Collections – Using Address Collections to Send to Multiple Recipients
  3. Flow Example 3 – Email with Attachments – Simple Email (1) With Attachments
  4. Flow Example 4 – Email Using Template – An email using a Lightning EmailTemplate
  5. Flow Example 5 – Multi-Lingual Using Email Templates – An email using a Lightning EmailTemplate selected by language
  6. Flow Example 6 – Mass Email – Send an email using MassEmail messaging

Choose the example you would like to see and the instructions are in each of the examples. You will also find in these examples the use of Text Templates for formatted Rich Text messages (Example 1), using Plain Text (Example 2), and logging the email as an activity on the related object (Example 5).

Select Test Flow and Start an example

To see how the Send Better Email Action is configured for each of these examples, click on the appropriate Action (they are labeled) and look at the Input Variables. You may also want to look at some of the logic in the setup to those examples for ideas in creating your own flows.

Flow Example 1 – Simple Email Text – with To, Sender, Reply-To, Subject, Body (All text)

Flow Example 1 sends a rich text email with content predefined in the resource HTMLTextTemplate to the addressee in [TO(TestMailAddress1)] from [Reply Email Address(TestReturnAddress)] with the name [Sender Display Name(testSenderName)] using [Subject(testSubject)] and [Body(HTMLTextTemplate)]

All of the above are flow resource variables. To create a body with line breaks, use a formula variable (see example resource variable testPlainTextLineFeeds)

Note: To get the full effect of rich text, edit the flow resource formula plainTextBody resource instead of modifying the field on this screen.

Flow Example 2 – Simple Email with Address Collections

Flow Example 2 – Simple Email with Address Collections. Addressees can be built from multiple collections. This example builds a collection of strings from the two email strings and/or from collections you can set up external to the example flow by creating contacts with names containing the text entered in [Contact Contains Match].

By default, this example builds a collection of strings from the two recipient email addresses and will send all collections to To, CC, and BCC (so 6 emails will be sent – minimum). The message contains rich text email with content predefined in the resource HTMLTextTemplate from [Reply Email Address(TestReturnAddress)] with the name [Sender Display Name(testSenderName)] using [Subject(testSubject)] and [Body(HTMLTextTemplate)] to the addressees in the collections.

Example: Create two contacts with valid email addresses and names containing “testContact”, then specify “testContact” in [Contact Contains Match]

Note: To get the full effect of rich text, edit the formula plainTextBody instead of modifying the field on this screen.

The resultant Parameter Editor is:

Flow Example 3 – Simple Email with Address Collections

For this example, you will need to create or use a record to which attachments can be made (e.g., a Contact). Create the record and then use the recordId of that record to attach files.

This sends out a simple plaintext email with attachments from uploaded files to the addressee in [Recipient Email Address] from [ReplyTo Email Address] with the name [Sender Name] using [Subject] and [Body]

All of the above can be created by assigning variables. To create a body with line breaks, use a formula variable (see example variable testPlainTextLineFeeds)

Note: This example as distributed uses the formula variable “testPlainTextLineFeeds” to create a plain text body without signature

Flow Example 4 – Email Using Template

This sends out an email using a specified EmailTemplate with the addressee specified through the TargetObjectId and optionally (dependent on your Template) merge fields with an associated object record using that record’s Id.

For this example, you will need to create or use a template. Templates also require that you have a recipient record (targetObjectId) (e.g., Contact, User, . . .) which must also pre-exist. You will be required enter the ID for that record as the (targetObjectId). Additionally if you intend to test merge fields (RelatedTo) with your template, you must also pre-create the related object record and have available the Id for that record as an ID for the Record Object Id (RecordId).

This example also creates an activity for the email which will be assigned to the running user and related to the RecordId.

You can create test templates (sendBetterEmailTest) by running example 5.

If you use the default test templates (sendBetterEmailTest) the Target ID should be a ContactId and the Related Record should be an AccountID.

Flow Example 5 – Multi-Lingual Using Email Templates

SendBetterEmail provides multi-lingual support within the same flow by allowing the language to be specified, then selecting the appropriate template for that language. For this functionality, each language localization has its own template with all localizations sharing a common EmailTemplate.Name. To differentiate the localizations, add a tag to the EmailTemplate.Description field in the format: ‘Language=”en_US”‘ (or whatever corresponding to your organization localizations)

This example uses the template set sendBetterTest with english (en_US) and spanish (es_MX) versions. If the templates do not exist, this example will automatically create them for you (sendBetterEmailTest).

You will also need to:

1) Create a Contact (for Target Object) and have its Id available.

2) Create an Account (for Related Record) and have its Id available.

You can, of course, vary the templates and object records to reflect your organization’s needs.

This sends out an email using a specified EmailTemplate with the addressee specified through the TargetObjectId and optionally (dependent on your Template) merge fields with an associated object record using that record’s Id.

For this example, you will need to create or use one or more templates. Templates also require that you have a recipient record (targetObjectId) (e.g., Contact, User, . . .) which must also pre-exist. You will be required enter the ID for that record as the (targetObjectId). Additionally if you intend to test merge fields (RelatedTo) with your template, you must also pre-create the related object record and have available the Id for that record as an ID for the Record Object Id (RecordId).

If you use the default test templates (sendBetterEmailTest) the Target ID should be a ContactId and the Related Record should be an AccountID.

Flow Example 6 – Mass Email – Send an email using MassEmail messaging

SendBetterEmail can also be used to send Mass Emails. Mass Emails are far more limited in functionality that Single Emails, though both can be bulked as a single send (up to 10) in this action. Mass emails cannot have language localization by target for obvious reasons (one template for a list of targets), so the selected language will apply to the entire list.

This example uses the template set sendBetterTest with english (en_US) and spanish (es_MX) versions. If the templates do not exist, this example will automatically create them for you (sendBetterEmailTest).

You can, of course, vary the templates and object records to reflect your organization’s needs.

This sends out an email using a specified EmailTemplate with the addressees specified through the TargetObjectIds and optionally (dependent on your Template) merge fields with an associated object record using that record’s Id (WhatId).

If you use the default test templates (sendMassBetterEmailTest) the Target ID and the RelatedRecord Id will be a UserId.