This post is inspired by Kristi Guzman who asked on Twitter whether she could have a logged activity update the related Lead’s status. I began researching and found that others were wondering the same thing. For example, Ahmad Helal submitted to IdeaExchange How to update a Case once a Task is completed. The short answer to both scenarios is yes, this is possible, though it may not seem too straight forward initially.
NOTE: If you have “Shared Activities” enabled in Setup | Activities | Activity Settings then please see my other post How to Update Leads or Contacts When Shared Activities Logged.
How Tasks / Events Relate To Other Records
- Related To (WhatId) can be related to any object that allows activities. For standard objects, this already includes Accounts, Opportunities, Campaigns, etc. For custom objects this must be enabled in the Setup page by selecting the Allow Activities option.
- Name (WhoId) can either be a Contact or a Lead.
The purpose of this post is to determine how we can make field updates to the Contact or Lead of a Task when it is non-deterministic which object the WhoId field references. The concept discussed can also be applied to the WhatId to make updates to Cases, Opportunities, Campaigns, etc.
How to Know Who or What a Task / Event Relates To
Unlike traditional lookup fields where the all values held in the field belong to a specific object type. For example, a lookup field to Account object only holds values of Account IDs. Both the Related To (WhatId) and Name (WhoId) task fields can hold record IDs from different objects.
So we need something to help us distinguish from one task to the other who or what the task relates to. And that something to help us is the 3 character object key prefix of the record IDs.
Every record ID in Salesforce is a “smart id” and the first three characters tell us which object the ID relates to. For example, IDs that start with 001 are for Accounts, and IDs that start with 003 are for Contacts, and IDs that start with 00Q are for Leads.
Automation Hour Webinar
On November 4, 2016, I guest presented on Automation Hour to teach how to implement this solution using Process Builder or Flow. Check out the below video, or, if you prefer text instructions and screen shots, skip down to the next paragraph =)
Process Builder Setup
- Create new Process that starts when “a record changes”.
- Choose the Task object and to start the process “when a record is created or edited”.
- Setup a Decision step for each object type the Task could be related to that you are interested in. For example, if you want to perform a field update on a related Lead then your Decision step’s criteria will check if the Name ID (WhoId) field starts with 00Q, the object key prefix for Lead. Add a second criteria to the Decision that checks if the Task’s Closed field is true (this is best practice to avoid having to setup criteria for multiple statuses if all you care about is if the task is marked complete).
- Configure the Immediate Action to do an Update Records action and choose “select a record related to the Task” then choose Name ID (Lead). The option to choose Name ID (Lead) or Name ID (Contact) are special options to make it easier for you to configure your action contextually even though it is truly unknown whether any given task that enters your process will or will not be related to a Lead or Contact at all. We guarantee a task record only enters this path based on our Decision criteria that inspects the first three characters of the related ID. As you can imagine, there are also convenient options for Related To (Account), Related To (Case), etc. for all other objects that support activities.
Overview of what the finished Process will look like:
Setup the first Decision step that checks if Task is related to a Lead and if the Task is completed:
Choosing the Record Updates immediate action to apply to the Lead related to the Task: