Getting Started with Process Builder – Part 27 (Email Notification for Draft Emails in Case Feed)

Getting Started with Process Builder – Part 27 (Email Notification for Draft Emails in Case Feed)

Last Updated on November 30, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

How do you send email notifications for the draft emails in the case feed? 

Draft emails allow support agents who use Case Feed, write and save messages without having to send them immediately. It also allows us to implement approval processes so that messages can be reviewed by supervisors or senior agents before they’re sent to customers. Drafts are only supported if your administrator has enabled them, but there is no such option to send reminder notifications for Draft emails


After reading this blog post, the reader will be able to:

  • Understanding Draft emails features for case
  • Create an email template in Flow
  • Understanding how to send notifications(email) for Draft emails using point and click tools

Business Use case

Warren Mason is working as a System administrator at Universal Containers (UC). Support agents from his organization are using the email draft feature and want some enhancements. Many times they compose a new email on Case Feed and save it as a Draft. Later on, they forget to send it, so they want a reminder notification (email) for Draft emails after 2hrs of its creation.

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario, but let’s use the Flow and Process Builder to solve the above business requirement. Apex Triggers can also be used to solve the above business use case. 

We are using Lightning Flow because (as of the Winter’21 release) Salesforce doesn’t allow us to create an email alert on the Email Message object. Hence we will use a Flow text template to construct the email and send it to the recipient.

Let’s take a pause here and review EmailMessage objects in Salesforce. Make sure to enable Email Drafts features by navigating Support Settings.

Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 2 steps to solve Warren’s business requirement using Flow and Process Builder. We must:

  1. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a record variable to store email message record details 
    3. Add a text template to create a dynamic email template  
    4. Add send email action  – to notify email message owner   
  2. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Set time for actions to execute
    5. Add action – flows 

Step 1.1: Lightning Flow – Define Flow Properties 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flows.
  4. Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. Click Done.

Step 1.2: Lightning Flow – Add a Record Variable to Store Email Message Record Data

  1. Under Toolbox, select Manager, then click New Resource to store email message record.
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varREmailMessage
    3. Data Type: Record
    4. Object Task
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.3: Lightning Flow – Add a Text Template to Create Dynamic Email Template

 Now we’ll create an email template using the Text Template. Text template allowed you to specify the multi-line messages.  It also allows you to use HTML code.

  1. Under Toolbox, select Manager, then click New Resource to create a text template. 
  2. Input the following information: 
    1. Resource Type: Text Template
    2. API Name: ttEmailBody
    3. Select View as Plain Text
    4. Body 
      1. Hi {!varREmailMessage.CreatedBy.FirstName},
      2. This is just a reminder email to notify you that, you have composed an email with Draft status on Case :- {!varREmailMessage.ParentId}
      3. Regards,
      4. Automation Champion
  3. Click Done.

Step 1.4: Lightning Flow – Add Send Email Action to Notify Email Message Owner

Now we will use the Send Email static action to send out an e-mail to Assignor. 

  1. Under Toolbox, select Element.
  2. Drag-and-drop Action element onto the Flow designer. 
  3. Select SendEmail out-of-the-box action. 
  4. Enter a name in the Label field; the API Name will auto-populate.
  5. Set Input Values
    1. Body: {!ttEmailBody}
    2. Subject: Email Draft Notification For Case {!varREmailMessage.ParentId}
    3. Email Addresses (comma-separated): {!varREmailMessage.CreatedBy.Email}
  6. Click Done.

In the end, Warren’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: 50
  5. Interview Label: Email notification for Draft email {!$Flow.CurrentDateTime}
  6. Click Save

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

Our next task is to create a Process on the Task object to Launch a Flow, only when a task is completed. To create a Process on the Task object, follow the instructions below:

Step 2.1: Define Process Properties

  1. Click Setup.
  2. In the Quick Find box, type Process Builder.
  3. Select Process Builder, then click New.
  4. Name the Process and click the Tab button. The API Name will populate. 
  5. As a best practice, always input a description
  6. The process starts when A record changes.
  7. Click Save.

Step 2.2: Define Evaluation Criteria

  1. Click on the Add Object node to begin selecting the evaluation criteria.
  2. Select the Email Message object from the dropdown list.
  3. Start the process when a record is created or edited.
  4. Click Save.

Step 2.3: Define Process Criteria

  1. Click the Add Criteria node to begin defining the process criteria.
  2. Name the criteria.
  3. The criteria should execute actions when the conditions are met.
  4. Set Conditions
    1. Row 1
      1. Field: Email Message | Status
      2. Operator: Equals
      3. Type: Picklist
      4. Value: Draft
    2. Click Add Row
    3. Row 2
      1. Field: Email Message | CaseID
      2. Operator: Is null
      3. Type: Boolean
      4. Value: False
  5. Select All of the conditions are met (AND)
  6. Click Advanced
  7. Select Yes to execute the actions only when specified changes are made to the record.
  8. Click Save.

The reason why we would select the Yes checkbox for the question — Do you want to execute the actions only when specified changes are made to the record? — is to allow the Process Builder to execute the actions only if the record meets the criteria now, but the values that the record had immediately before it was saved didn’t meet the criteria. This means that these actions won’t be executed when irrelevant changes are made.

Step 2.4: set time for actions to execute

  1. Below Scheduled Actions, click Set Schedule.
  2. Set Field Values:
    1. Row 1:
      1. 0
      2. Hours
      3. After
      4. LastModifiedDate
  3. Click Save.

Step 2.5: Add Action – Flows

  1. Below 0 Hours After LastModifiedDate Scheduled Actions, click Add Action.
  2. For Action Type, select Flows
  3. Name the action.
  4. Select the flow we just createdEmail notification for Draft email.
  5. Set Flow Variables: 
    1. Row 1:
      1. Flow Variable: varREmailMessage
      2. Type: Field Reference
      3. Value: Select the Email message record that started your process
  6. Click Save.

In the end, Warren’s Process will look like the following screenshot:

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

Proof of Concept

Now onwards if a user leaves the email (which he compose through Case Feed) in Draft status, the process builder will notify him after 2 hours.

  1. Now compose an email (By navigating the case detail page) and save it as a draft as shown in the following screenshot:
  2. You will get an email from Salesforce after 2 hrous, if the email is still in Draft status.

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?

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!


Leave a Reply

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