Send, Log, Repeat: Logging Email Alerts as Activities

Send, Log, Repeat: Logging Email Alerts as Activities

Last Updated on October 24, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • How do you log emails sent with the ‘send email’ action?

Objectives:

After reading this blog, you’ll be able to:

  • Use record-triggered flow to send out an email alert.
  • Use the “Send Email” flow action.
  • Use email template with the “Send Email” action without creating an email alert.
  • Log emails sent with the “Send Email” action.
  • And much more.

👉 Previously, I’ve penned several posts on how to send email alert using Salesforce Flow. Why not check them out while you are at it?!

  1. Email Notification on Password Expiration
  2. Want to Send an HTML Email from Salesforce Flow? Oh, yes! It can be done!
  3. Send a Welcome Email with Attachments to New Users Using Salesforce Flow
  4. Custom Email Notification for Completed Tasks
  5. Email Notification on Topic Assignment

Business Use case

Benjamin Moore, a Salesforce Administrator at Gurukul On Cloud (GoC), has been assigned a specific task. Once a case is successfully closed, he should:

  1. Send out an email alert to the customer asking for their feedback.
  2. Log the sent email in the case and contact records for future reference.

Automation Champion Approach (I-do):

With the latest release from Salesforce, now it is possible to automatically log emails to a record’s Activity Timeline when using the Send Email action. This enhancement offers users the flexibility to:

  1. Log emails to recipient records – this encompasses leads, contacts, and person accounts.
  2. Log emails to non-recipient records, such as accounts, cases or opportunities.
  3. Conveniently log emails to both recipient and non-recipient records simultaneously.

Prior to this release, emails sent using the Send Email action couldn’t be automatically tracked in Activity Timelines. As of Spring’24 release, it is not possible to log emails sent to users; otherwise, you will get an error.

saveAsActivity must be false when sending mail to users. WhatId is not available for sending emails to UserIds.

Before proceeding, you should become familiar with the EmailTemplate object in Salesforce. It represents a template for an email, mass email, list email, or Sales Engagement email. Supported in first-generation managed packages only.

Field Name Details
Name Name of the template. Label is Email Template Name.
RelatedEntityType When UIType is 2 (Lightning Experience) or 3 (Lightning ExperienceSample), RelatedEntityType indicates which entities this template can be used with. Valid values are the entity API name: “Account” for account, “Contact” for contact, “Opportunity” for opportunity, “Lead” for lead, and so on. The value can be any entity the user has read access to (including custom entities) but not virtual entities, setup entities, or platform entities.
 
To solve this requirement, we will use the After-save Record-Triggered FlowCheck out this article to understand why we are using after-save record-triggered flow for this scenario.
 
Before discussing the solution, let me show you a diagram of the process at a high level. Please spend a few minutes going through the following Flow diagram to understand it.
 

Let’s begin building this automation process.

Guided Practice (We-do):

There are 6 steps to solve Benjamin’s business requirement using Record-Triggered After-Save Flow. We must:

  1. Create an email template
  2. Define flow properties for record-triggered flow
  3. Add a decision element to determine if the case has been closed
  4. Add a get records element to find the email template
  5. Add a decision element to check if the email template was found or not 
  6. Add send email action  – to send and log the email

Step 1: Create an Email Template 

  1. From the App Launcher, find and select Email Templates.
  2. Clicks on the New Email Template
  3. Enter a Name, Related Entity Type, Folder, Subject and Body for your email template.
     
  4. Save your template when you’re done.

Step 2: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Record-Triggered Flow option, click on Create
    1. Object: Case
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Conditions: None
    4. Optimize the Flow For: Action and Related Records 
  5. Click the X at the top to save your changes.

Step 3: Using Decision Element to Check If the Case Has Been Closed

Now we will use the Decision element to check if the case was closed or not. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource{!$Record.IsClosed}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: Only if the record that triggered the flow to run is updated to meet the condition requirements
  6. Click Done to save your changes.

Step 4: Adding a Get Record Element to Find the Email Template

The next step is to use the Get Records element to find the email template created in step #1.

  1. On Flow Designer, below the Decision node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the EmailTemplate object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: Case Closure Feedback Request
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click the X at the top to save your changes.

Step 5: Using Decision Element to Check If the Email Template Was Found or Not

Now, we will use the Decision element to check if the previous Get Records element returns open opportunities record. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Get_Email_Template}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 6: Add Action – Send and Log Email Alert

Now we will use the Send Email static action to send out an e-mail alert and log email. 

  1. Under the Found node, click on the +icon and select the Action element.
  2. Search and select the Send Email from the dropdown menu
  3. Label the new action Feedback Request Email to Client
  4. Set Input Values
    1. Email Template ID: {!Get_Email_Template.Id}
    2. Log Email on Send: {!$GlobalConstant.True}
      1. Note:- Indicates whether to log the email on the specified records’ activity timelines. Valid values are true and false. Default value is false, and the email isn’t logged. To log an email, you must specify a value in Recipient ID or Related Record ID. If Log Email on Send is set to true, it changes the API called by the action, which can impact your daily email-sending limit. 
    3. Recipient ID: {!$Record.ContactId}
      1. Note:- The ID of a lead, contact, or person account to send the email to. If Log Email on Send is included, then Recipient ID is the ID of the record where the email is logged. If Email Template ID is included, then Recipient ID is required.
    4. Related Record ID: {!$Record.Id}
      1. Note:- The ID of a non-recipient record. For example, the ID of a case record. If Log Email on Send is included, then Related Record ID is the ID of a secondary record to log the email to. In this case, the email can’t be logged if Recipient ID is a lead record. If Email Template ID is included, then Related Record ID is the ID of the non-recipient record used to populate email template merge fields.
  5. Click the X at the top to save your changes.

In the end, Benjamin’s Flow will look like the following screenshot:Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 59
  5. Interview Label: Log Emails Sent with the Send Email Action {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate button. 

Proof of Concept

From now on, if a support agent closes a case, the record-triggered after-save flow we’ve created will be triggered. It will do thew following: 
  1. Send an email alert to the customer
  2. Log the email to the case, and
  3. Also log the email on the contact

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
 
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!
Preferred Timing(required)

2 thoughts on “Send, Log, Repeat: Logging Email Alerts as Activities

Leave a Reply

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