How To · Uncategorized

Standard Email Message Object Process Builder/Flow Use Case: Create Task when Follow Up Email Sent

EmailMessage

Salesforce introduced email message as its own standard object in Summer 16. FINALLY, it is no longer a task in Salesforce! Now, that it is its own object, you can add custom fields, write validation rules, triggers, process builder and flows.

The email addresses are stored as text fields with no association to the user or contact or lead.

There is a junction object called EmailMessageRelation that holds the FromAddress, ToAddress, CCAddress, BCCAddress for a given EmailMessageID.

Here are the fields available in the EmailMessageRelation.

EmailMessageRelation.JPG

If we want to identify the contact in the ToAddress from the email message for further use in Salesforce, we need to pull the ID from the RelationID field where the RelationType is “ToAddress” and RelationObjectType  is “Contact.” Note: You can similarly pull this information for a lead where RelationObjectType is “Lead.”

Here are a few lessons learned from implementing this use case:

  • The new email message standard object introduced in Summer 16 stores email message records in its own object, removed from the task object. In the standard object, all the email information is now parsed and stored in individual fields – to address, from address, CC address, BCC address, subject, email body and attachment.
  • The email recipient information in the email message record is the email address sent. In order to lookup to the contact for the task, we need to pull the RelationId from the EmailMessageRelation object for the contact lookup.
  • Use process builder with the help of visual workflow to update a custom contact field based on the relationID associated to the ToAddress and then create a task for any email that contains the phrase “follow up.”
  • Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes noting the data stored in a custom field, providing the purpose of a process builder, etc.

 

Business Use Case: Addison Dogster is a system administrator at Universal Container. Sally Sunshine is the Sales Manager. When a Sales Rep sends an follow up email to a customer, he would like Salesforce to create a task assigned to the Sales Rep to follow up with the contact three days after the email was sent.

Solution: Being the Awesome Admin that she is, Addison is able to solve this declaratively using custom lookup field to track the contact ID. For follow up emails, Addison will use process builder to invoke visual workflow to lookup the RelationID from the EmailMessageRelation object using the EmailMessageID, RelationType and RelationObjectType to update the custom contact field and then using process builder, will create a task for the sales rep associated to the contact. All of this is done with clicks, not code. Hooray!

Quick Steps:

1.Create a custom lookup field called “Contact” to the Email Message object. For those using Salesforce Classic, you can create custom fields by going to Setup | Customize | Email | Email Message | Fields.

ContactLookupField.JPG

Best practice tips:

  • Don’t forget to provide a description so you and other/future admins know what this custom field is used for.
  • Set the FLS (field level security) for each profile. Only make the field visible and editable for the profiles that need it. Do not just click the “Next” button when you are on the screen.
  • Leave this field off the page layouts since this is a processing field. By default, new fields are added to the page layout.

 

2. Create the visual workflow to lookup the RelationID from the EmailMessageRelation object using the EmailMessageID, RelationType and RelationObjectType to update the custom contact field.

Flow-UpdateContactFieldonEmailMessage.JPG

A. We will create 2 variables upfront. The varEmailMessageID will be passed as a parameter from process builder. The varContactID variable will store the RelationID queried from the RelationEmailMessage object.

varEmailMessageID.JPG

varContactID.JPG

B. We will create a Record Lookup to the EmailMessageRelation object where the EmailMessageId equals the variable varEmailMessageID, RelationObjectType equals “Contact” and RelationType equals “ToAddress.” Once the record is found, save the RelationID value in the second variable varContactID.

Best practice tips:

  • Provide a description so you and other/future admins know what this flow element is used for.
  • Check the box next to Assign null values to the variable(s) if no records are found so your flow doesn’t fault when no records are found.

 

The end result looks like this…

Flow-UpdateContactFieldonEmailMessage-LookupEmailMessageRelation.JPGFlow-UpdateContactFieldonEmailMessage-LookupEmailMessageRelation1.JPG

Double click on the flow element box to set it as the start element. If set properly, this will show with the green down arrow.

Flow-UpdateContactFieldonEmailMessage-SetStartElement.JPG

C. Next, we will create a Record Update flow element that will update the EmailMessage object where the Id equals the variable varEmailMessageID. Once found, we will update the Contact field with the variable varContactID.

Best practice tip: Provide a description so you and other/future admins know what this flow element is used for.

The end result looks like this…

Flow-UpdateContactFieldonEmailMessage-RecordUpdateEmailMessageJPG.JPG

Flow-UpdateContactFieldonEmailMessage-RecordUpdateEmailMessage1.JPG

D. Draw the connectors between the Record Lookup and Record Update flow elements.[Note: The visual flow diagram includes the Record Lookup element: Using Custom Metadata Type in Visual Workflow Fault Email.

Flow-UpdateContactFieldonEmailMessage1.JPG

As a best practice, where there is a DML action (fast or record create, update, delete or lookup action) in a flow, you should also include notification of a flow fault.

Note: To avoid “hardcoding” email addresses in a fault email, refer to a post Using Custom Metadata Type in Visual Workflow Fault Emails.

Select the Send Email flow element that is listed under Static Actions, not under Quick Actions.

Best practice tip: Don’t forget to provide a description so you and other/future admins know what this send email element is supposed to do.

Configure the body to show the fault message, subject and email address(es).

Body: Fault Message: {!$Flow.FaultMessage}

Subject: Error: Update Contact Field on Email Message

Email Addresses (comma-separated): <email address>

Flow-UpdateContactFieldonEmailMessage-SendFaultEmail.JPG

You will need to draw a connector line between the Record Lookup, Record Update and Send Email elements.

Can’t seem to get the fault connector to appear? Create a temporary flow element (circled below), draw your first connector to that temporary flow element. Then, draw another connector to the send element. This connector has the word “FAULT” in it.  Once that is completed, delete the temporary flow element you created.

This is the end result.

[Note: The visual flow diagram includes the Record Lookup element: Using Custom Metadata Type in Visual Workflow Fault Email. If you choose not to implement that, you can omit the flow element Record Lookup before the Send Email flow element.]

Flow-UpdateContactFieldonEmailMessage1.JPG

E. Click on the Save button and provide the following information as the flow properties.

Best Practice Tip: Don’t forget to provide a description so you and other/future admins know what this visual workflow is for.

Flow-UpdateContactFieldonEmailMessage-Properties.JPG

F. Click the “Close” button.

G. On the flows screen, activate the flow.

3. Lastly, let’s create the process builder for the Email Message object called “Email Process” and click the “Save” button.

ProcessBuilder-EmailProcess.JPG

In Salesforce Classic, process builder can be found in Create | Workflows & Approvals | Process Builder. Click on the New button to create a new process builder.

ProcessBuilder-Properties.JPG

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this process builder is used for.

A. Select “Email Message” as the object. Select to start the process “when a record is created or edited” and click the “Save” button.

ProcessBuilder-EmailProcess-EmailMessageObject.JPG

B. Let’s set the first criteria node. We will call it “Follow Up Email Sent.” We want this to execute when a record is new AND the email body OR email subject contains the words “follow up”. There is no ability to set the criteria to a new record, we need to go the formula route.

Set the Criteria for Executing Actions to “Formula evaluates to true”

Insert this formula into the Formula box::

ISNew() &&

(

CONTAINS([EmailMessage].HtmlBody , “follow up”) ||  

CONTAINS([EmailMessage].Subject , “follow up”)

)

The end results looks like this…

ProcessBuilder-EmailProcess-FirstCriteriaNode.JPG

As an immediate action, we will invoke the visual workflow created in Step 2.

Action Type: Flows

Action Name: Update contact field

Flow: <Locate the flow created in Step 2>

Set the variable varEmailMessageID Reference [EmailMessage].Id

End result…

ProcessBuilder-EmailProcess-FirstCriteriaNode-ImmediateAction.JPG

C. Let’s set the second criteria node. We will call it “Create Task for Follow Up Email.” We want to create a task if the email body or subject contains “follow up” and the contact field is not blank and has changed.

We want this to execute when the following criteria is met:

  1. [EmailMessage].HtmlBody Contains String follow up
  2. [EmailMessage].Contact__c Is null Boolean False
  3. [EmailMessage].Contact__c Is Changed Boolean True
  4. [EmailMessage].Subject Contains String follow up

Set the condition to “Customize the logic.”

Logic: (1 or 4) and (2 or 3)

End result…

ProcessBuilder-EmailProcess-SecondCriteriaNode.JPG

Now, let’s create an immediate action, we will create a new record.

Action Type: Create a record

Action Name: Create a follow up task

Record Type: Task

Set Field Values:

  • Due Date Only Formula today()+3 [We are setting the due date to 3 days from today]
  • Assigned To ID reference [EmailMessage].CreatedById
  • Priority Picklist Normal
  • Status Picklist Not Started
  • Subject Formula “Follow up on ” & [EmailMessage].Subject & ” for ” & [EmailMessage].ToAddress [Note: The task subject will indicate to “Follow up on <Email subject> for <Email address>]
  • Name ID Reference [EmailMessage].Contact__c

End Results…

ProcessBuilder-EmailProcess-SecondCriteriaNode-ImmediateAction.JPG

D. Go back to the first criteria and click on the Stop button, select “Evaluate the next criteria” and save.

This is a new feature in Summer 16 which allows you to specify for each node (not containing a scheduled action) whether to stop evaluating or to continue to the next criteria.

ProcessBuilder-EmailProcess-EvaulateNextCriteria.JPG

E. Now, you are ready to activate your process builder. Click on the “Activate” button.

ProcessBuilder-EmailProcess-Activate.JPG

That’s it! Congrats! You’ve implemented a process to create a new task for email messages sent to a contact with the words “follow up” in the email body or subject.

Now, before you deploy the changes to Production, you need to test your configuration changes.

  1. Login as a user and navigate to a contact to send an email. Ensure either the email body or email subject contains the words “follow up.”
    1. Verify the custom contact lookup is updated on the email message record.
    2. Verify that a new task has been created assigned to the user, associated to the contact to follow up on the email sent, with a due date 3 days after today.
  2. Login as a user and navigate to a contact to send an email. Ensure either the email body or email subject DOES NOT contains the words “follow up.”
    1. Verify the custom contact lookup is NOT updated on the email message record.
    2. Verify that no task is created.

Deployment Notes/Tips:

  • The new custom field, process builder and visual workflow can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
  • The field level security for the custom email message field will need to be manually updated post deployment. I would caution against adding the related profiles in the changeset for deployment as the results of deploying a profile are not reliable. If you have a tool like Snapshot by Dreamfactory, you can use the tool to deploy field permissions.
  • Activate the process builder and visual workflow as they are deployed as inactive into Production.

Advertisements

4 thoughts on “Standard Email Message Object Process Builder/Flow Use Case: Create Task when Follow Up Email Sent

  1. Great to Know about the new object. Also, ‘Execute The Next Criteria’ feature in the Process flow is exciting. Just wondering if there would be any feature like -“Jump to X criteria” :).

    Like

  2. It moves emails out as tasks into its own object. I don’t believe it impacts email alerts but to be sure, I’d suggest testing it out.

    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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s