UPDATE 4/2/2017: New solution available!
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
Tasks and Events (aka Activities) have two special lookup fields: Related To (WhatId) and Name (WhoId), which each are lookups to multiple objects (i.e. polymorphic).
- 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.
Photo Credit: Salesforce Hacker
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.
Learn more about Object Key Prefixes on this Salesforce help article and and this community post by Daniel Ballinger (@FishOfPrey).
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:
My friends it seems like a complex solution.
LikeLike
Hi Ashley,
Thanks for sharing the feedback. I’d like to help clarify any issues that you’re finding complex. The solution is a workaround because Salesforce doesn’t natively support cross-object field update on the Task record to the Related To (WhatId) or Related Name (WhoId) so the trick is to copy the ID value held in those fields over into custom lookup fields that are of a specific type (e.g. lookup to Lead or lookup to Contact) and then do normal Process Builder actions on Task object referencing those custom fields.
Let me know if I can be of any assistance.
Thanks,
Doug
LikeLike
Hi Doug,
I just came across this issue yesterday so your post was timely. For my use case I want to update the Contact Status when an Event subject starts with “Meeting With”. It seems as though with the Event object I am unable to access this Contact Lookup field as I could when updating Tasks. Everything is the same until I get to the Update Records action and there is no Contact field to select to update as it was with Tasks. Can you help me with a work around? Maybe I’m missing something with the Event object that is different then with Tasks?
LikeLiked by 1 person
Hi Eli!
This works for me. See my screen shots here: http://imgur.com/a/s21IW
I created a new Process Builder on the Event object then setup an Update Records action and referenced the custom Contact lookup field just like when creating the process on Task object. My guess… maybe try navigating back into Process Builder page (perhaps something was cached) or even that your profile has field-level access to the field (I don’t believe that’s an issue in Process Builder, but I know not having FLS to a field makes it not show up in Flow designer).
Doug
LikeLike
Thanks for the reply Doug. What your screen shots show is working for me too (when the custom field is populated). Where I’m running into an issue is on the first PB you have – trying to populate the custom field on the Event record in order to use the second PB to update the record. For the first PB my criteria node is Event.WhoID starts with Formula “003” (works fine), for my actions – Record Type = Event and when I try to locate the custom Contact lookup field it isn’t available to be selected like it was for the Task and therefore I can’t set this field so the second PB doesn’t work since the first one isn’t able to set the Contact field. Let me know if I am just missing something or if there is a work around. I appreciate your help on this!
LikeLiked by 1 person
Thanks for the detailed steps and clarification. Well… it works for me in the first process builder too. When defining the immediate action of Update Records, I choose Record Type = “Select the Event record that started your process”, whch then displays [Event] once I click Choose button. Then when choosing which field to update, I see the standard fields plus my custom Contact and Lead lookup fields.
The only thing I can think of is that tonight Process Builder was acting very slow. When I would click in to the field chooser to pick the field to update, in the first few seconds if I tried to type a field name and use autocomplete it would say “No results found”. But after about 5 seconds or so then that field chooser component initialized and then showed the drop down of available fields that I could then pick my custom Contact lookup field to update.
To continue troubleshooting, would you be open to making and sharing a quick screen recording with https://screencast-o-matic.com or post some screen shots to http://imgur.com (or wherever).
Sorry I can’t be of more help at the moment as I don’t think I’m having the same issue as you at the moment.
LikeLike
Hi Doug, I just got out of a client meeting and am free for the next hour if you are available to do a screen share. If not I would love to catch up at a time that works best for you. I’m not sure if posting screen shots of something that isn’t there makes much sense?
Thanks as always!
Eli
LikeLiked by 1 person
Hi Eli, does your org perhaps another custom object labeled “Event” and you chose it in Process Builder instead of the standard object?
LikeLike
Hi Doug,
Let me check after I get my kids to bed (about 30 min) – it’s entirely possible. Are you free in about 30 in the event that isn’t the case? If not we can surely catch up sometime next week like you suggested.
Best, Eli
LikeLike
Hey Doug,
I got this to work brilliantly in my dev org so I think I’m good to go now and re-look at the customers instance again that I was trying this in.
Thanks for your help and support!
Have a great weekend, Eli
On Fri, Jun 24, 2016 at 7:40 PM, Douglas C. Ayers wrote:
> Doug Ayers commented: “Hi Eli, does your org perhaps another custom object > labeled “Event” and you chose it in Process Builder instead of the standard > object?” >
LikeLiked by 1 person
That’s great! Have a good weekend!
LikeLike
This is great! I have been using the Rollup Helper app to do this type of things but this is much better (free). Thank you!
LikeLiked by 1 person
Thanks for the kind feedback, Marie! Glad you like it 🙂
LikeLike
NICE! This will be huge, Doug. Thank you for sharing.
LikeLiked by 1 person
Hi Doug! This looks so close to what I’m trying to do. Currently doing this with a combination of flow and process builder, but I can’t wrap my head around how I can set an OR criteria for the existing lead status before the action is taken. For Example, I’d like to change the status to “Attempted” only if the current status is EITHER “Raw” or “Open”. I’m noticing that you can’t define logic in the immediate action criteria. Any ideas?
LikeLiked by 1 person
Hi Evan,
You are right that you can’t do OR criteria when specifying Update Records action. However, you can when defining the Decision element leading to your action.
In your process that checks the Task and has the criteria step to see that the Lead lookup is not null, add another condition to that decision that references the Lead’s current status. That way your immediate action to change the lead’s status only is run if it’s current status is what you’re looking for.
Make sense?
Doug
LikeLike
Hey Doug – I’m looking to actually do this. What I’m struggling with is how to add things to a decision element that let me lookup the Status of the Lead. However, I’m only seeing options to look at fields on the Task.
My other comments revolve around the same challenge. Any help you can provide is huge! Thanks again.
LikeLiked by 1 person
Hi Tim, just closing the loop here. I believe I answered and you confirmed this resolved in our thread at https://douglascayers.com/2016/06/21/salesforce-how-to-update-lead-or-contact-when-activity-logged/comment-page-1/#comment-1383
Thanks,
Doug
LikeLike
Doug, this is a very creative solution and I completely understand that this is a workaround to a salesforce limitation so I applaud your solution from that perspective, but I also wanted to point out as someone else mentioned this is a fairly complex solution with having to create additional lookup fields and multiple process builders just to update a single field. As a previous poster mentioned, you could use Rollup Helper to do this….very quickly in fact, with no additional lookups or multiple process builders, etc. There is also a free version of Rollup Helper where this could be implemented once per day if the client did not want to purchase our premium product that has real-time. The Rollup Helper admin would just need a single rollup of the number of completed tasks on a contact or lead via rollup filtering and then update a field on the contact or lead directly with the information required. From there, the admin could just create a traditional workflow field update or a process builder field update to update the lead status field. The solution would have less clicks and be less confusing imho with fewer lookups to document and worry about in reporting. Disclaimer: I work for Passage Technology the company that makes Rollup Helper.
LikeLiked by 1 person
Hi Jerry,
Thanks for the kind words and feedback!
I’m not sure that using a roll up helper app is any less complicated. For simplicity in comparing the two, I’m going to refer below to this post’s solution as the “PB” solution and the roll up helper solution as “RH”.
(1) Both solutions require setup of something to know that a Task was created or updated against a Lead.
– PB need a process or workflow rule to check the WhoId and populate a custom lookup field.
– RH needs to install an app then configure it to populate a custom field to store aggregated value.
(2) Both solutions need to take action once the triggering field has been set.
– PB uses another process or workflow rule to detect the lookup field change and any other desired criteria then does the field update on the related contact or lead.
– RH uses another process or workflow rule to detect the aggregate field change and any other desired criteria then does the field update on the related contact or lead.
(3) With both solutions, the admin must document the purpose of the field and the process/workflow rule/roll up scenario.
I don’t exactly see one solution as better or worse than the other. To me it’s “six of one, half-dozen of another.”
The purpose of this post was to show how this can be done natively on the platform using #ClicksNotCode.
For openness, and definitely nothing against you or Passage Technology because I’ve not used your app yet, but if someone were to use a roll up helper app for this solution, I would recommend Andy Fawcett’s free, open source app which I’ve used on dozens of projects https://github.com/afawcett/declarative-lookup-rollup-summaries/blob/master/README.markdown
Thanks,
Doug
LikeLike
Doug,
That comparison is fair and thank you for your contributions to the community! I guess I just get a little caught up in having to create a new duplicate additional lookup field which can get confusing to a new admin in an org. Also, fwiw, would like to mention that there is also a free version of Rollup Helper. Also, we do provide support for Rollup Helper if anybody needs help with setup or operation.
LikeLiked by 1 person
You are right, the extra lookup field can be confusing if it’s not named clearly or the related list it generates isn’t labeled clearly either. When setting up a page layout someone without understanding of the two fields may accidentally put the wrong related list on a page layout.
LikeLike
Hi Doug, I’m trying to populate the WhoID fields on the task record, but it’s not working. can you help? I keep getting an error message that it failed to trigger a flow and I think that I have tried every possible combination of solutions that I can think of.
LikeLiked by 1 person
I am also getting the same issue: An error occurred at element myRule_1_A1 (FlowRecordCreate).
INSERT — INSERT FAILED — ERRORS : (FIELD_INTEGRITY_EXCEPTION) Related To ID: id value of incorrect type: 0031700000VHNcKAAX
I have confirmed that the rollup fields are working as expected.
LikeLiked by 1 person
The task I was trying to create cracked here:
Related to ID: Reference: Contact ID Helper
LikeLiked by 1 person
Hi Adam,
It looks like you might be trying to associate a contact id (starts with “003”) to the Task object’s “Related To” field which doesn’t support contact ids but does support account, opportunity, campaign, etc. ids.
Thanks,
Doug
LikeLike
Julie, I think I figured it out. Make sure when you are creating your task that you are using ‘Name ID’ and not ‘Related to ID’.
Alternatively, you could do what was suggested here in one of my Community posts: https://success.salesforce.com/answers?id=9063A0000019Nzi
LikeLiked by 1 person
Glad you got it solved, Adam! Mayank is an awesome person in the community!
LikeLike
Hi Julie,
In your Process Builder, make sure you are not trying to overwrite the WhoId field but rather are copying its value into a custom lookup field. The custom lookup field you copy the WhoId value into (a lead lookup field or contact lookup field) depends on the first three characters of the ID. If the WhoId starts with “003” then you want to copy that value into a custom contact lookup field. If the WhoId starts with “00Q” then you want to copy that value into a custom lead lookup field.
Also, when you receive the error message “failed to trigger a flow” then the administrator who last activated that process or related flow will receive an email from Salesforce with all the nitty gritty details of what blew up. Could you share that with me if you’re still having issues?
Thanks,
Doug
LikeLike
Hi Doug,
I did what Adam recommended and I still got the error message. It’s posted below.
Also, I put the question on the community with a couple of screenshots. You can find it in this community group but the second screenshot is now slightly different. https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000001rzc
Here are the error details
Flow Details
Flow Name: TASK_Populate_WhoID
Type: Workflow
Version: 9
Status: Active
Flow Interview Details
Interview Label: TASK_Populate_WhoID-9_Task
Current User: Julie Curry (00560000002p1c6)
Start time: 8/10/2016 5:38 PM
Duration: 0 seconds
How the Interview Started
Julie Curry (00560000002p1c6) started the flow interview.
Some of this flow’s variables were set when the interview started.
myVariable_old = 00T6000004zgc4bEAA
myVariable_current = 00T6000004zgc4bEAA
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = “8/10/2016 5:38 PM”
LikeLiked by 1 person
Hi Julie,
Thanks for the details. Your screen shots on the success community post were helpful too. I answered there too and am copying my response here:
You’re pretty close! In your first attached screen shot, change the condition criteria to reference [Task].WhoId instead of [Task].Lead_WhoID__c.Id. Then in your second screen shot, change the Value to reference [Task].WhoId.
With those suggested changes that will make your process (1) evaluate the Task’s WhoId (displayed as “Name” lookup field on Task page layout) then (2) assign that WhoId value to your custom lookup field “Lead (WhoId)”.
Thanks,
Doug
LikeLike
Thanks, Doug! It worked!!!
YAY! I was looking for “whoID” in the picklist.
This is awesome!
LikeLiked by 1 person
Awesome!
LikeLike
Hi Doug,
Any chance you I could get your thoughts on the second half of what I’m trying to set up here. I want to create a formula in process builder, but I have no idea how to get what I want
best,
Julie
LikeLiked by 1 person
Hi Julie,
Sure, what are you wanting your formula expression to do?
Doug
LikeLike
Hi Doug,
Thanks for your response.
Here is a link to what I posted on the community. What they are suggesting may be the only options, but let me know if I’m wrong.
https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000001oBC&fId=0D53A00002p0N37&s1oid=00D300000000iTz&OpenCommentForEdit=1&emkind=chatterCommentNotification&s1nid=0DB30000000072L&emtm=1471288640565&s1uid=00530000009qwPx&fromEmail=1&s1ext=0
LikeLiked by 1 person
Gotcha! I’ve posted an answer to your success community post. Thanks!
LikeLike
Hi Doug, maybe a n00b question here, but how do I select the {Task].WhoId field for the criteria in Process Builder? Is it hiding in the dropdown field list somewhere?
LikeLiked by 1 person
Name ID is what you want
LikeLiked by 1 person
Hi Brandon,
As Adam also wrestled with and figured out, what you’re looking for is called Name ID.
Salesforce’s terminology is very inconsistent in this area unfortunately. In Process Builder, when choosing a field for the criteria expression it is labeled Name ID which is the same as the WhoId (the API name of the field) which is the same as the Name field that you see on the Task page layout.
Let me know if you have any other questions!
Doug
LikeLike
Thanks Adam & Doug! I’m still running into a few issues as I tweak your example. I’ve set it up with the Lead Lookup field on the Event record and the 1st process seems to correctly populate with that lookup field with the name of the Lead. However, for the 2nd workflow, I’m trying to update a checkbox on the Lead Record when the Event is a certain type (from a picklist field on the Event). Thus far, that checkbox is not being checked in my testing of the process. Is that because when the Event is created, that Lead Lookup field isn’t populated yet, or is there some other reason?
I’m sure some screenshots of my process would be useful, but doesn’t seem to be a way to add screenshots directly into this comment. However, a few comments about what I did differently from your example (besides using Event instead of Task):
For the Criteria, I look for one of two particular values from a picklist field and whether the lookup field is not null, using custom logic of (1 OR 2) AND 3
For the Action, I use the Record “[Event].Lead Lookup” (my lookup field) and just go ahead and set the Checkbox field on the Lead to “True” without any conditions
Anything obvious I should be looking for?
LikeLiked by 1 person
Hi Brandon,
Is your second process builder set to run on create and edit? It is important to run on edit because the first process will update the Task to have the custom lead lookup field populated.
You may upload screenshots to imgur.com then share the link here.
Thanks,
Doug
LikeLike
Hi Doug,
The second process is currently set to run on create and edit.
Here are screenshots of the 3 components of the process. Let me know if you see anything obvious.
Process Start: https://www.evernote.com/l/AJOmz0_LE1hJ0piFeEhvDMWfiWx4hf4IAqI
Criteria: https://www.evernote.com/l/AJMdHEe08gpOiahLaKHS4vejCPA-R1HAoBg
Action: https://www.evernote.com/l/AJPHmFGzng5CYK1pmu0gPjhvfWv4MncvLRU
Thanks!
Brandon
LikeLiked by 1 person
Yay…figured it out. I wasn’t allowing the process to run multiple times on the same transaction. It’s working like a charm now. Thanks for all your help!
LikeLiked by 1 person
Excellent!
>
LikeLike
Hey Doug,
I’m having some issues with the last step.
I have no issue populating the ID field with WhoId,
I create the criteria for the second process,
But when I get to “Immediate Actions” to update the related lead, I can’t find a place to enter “Record: [Task].Lead” (or in my case [Task].Related_Lead).
I click “Add Action”, then under Action Type select “Update Records”… Then it asks me to name it, and gives me a field called “Record Type”. Nowhere in the Record Type can I select my field to reference.
Am I doing something wrong?
LikeLiked by 1 person
Hi Brady,
Thanks for the detailed notes, you are very close! The Record Type option is to tell Process Builder if you want to make a field update to the current record (the one that started the process) or to a related child record. You want to choose the first option, “Select the Task record that started your process”. Once you’ve done that then Process Builder will show a new section in your Update Records action where you can now choose the fields you want to update, such as your custom lead lookup field “Related Lead”.
Let me know if you have any other questions! And sorry for the delay, I’ve been moving to a new house and starting new job all at the same time (I don’t recommend doing both simultaneously!)
Thanks,
Doug
LikeLike
Hi Doug,
Here is the point that I’m getting to.
As you can see, there doesn’t seem to be any “Record*” field that’s showing up on yours, or any way for me to aim salesforce at the Lead ID I’ve populated.
LikeLiked by 1 person
Hi Brady,
To confirm, is your screen shot referring to (1) the process that will populate the custom Lead lookup field on your Task object, or is it (2) the process that you want to use to update the related Lead fields after the first process has populated the lookup field?
Thanks,
Doug
LikeLike
This is the process I want to use to update the related lead field.
The process that populates the appropriate task field with the WhoId has already been created and works.
LikeLiked by 1 person
Ok, then my recommendation is that in your Update Records action, change the Record Type option from [Task] to [Task].Related_Lead__c and then you’ll be able to choose fields from the Lead object to make changes to.
LikeLike
Unfortunately I don’t seem to be able to do that.
It won’t let me simply type in the Record Type field.
If I select the Task record that started the process, it will just be “[Task]”
And if I try and chose a different one, it won’t find my custom field. (Mine is Named “Related Lead”)
LikeLiked by 1 person
Try typing just Related instead of including the [Task] prefix on that screen.
LikeLike
LikeLiked by 2 people
Any ideas on how to handle “Shared Contacts”? There’s a known issue with accessing Shared Contacts (TaskWhoRelation) via Apex so I’m plan b’ing it to Process Builder and the Declarative Rollup package. Here’s the known issue:
https://success.salesforce.com/issues_view?id=a1p30000000Su0FAAS
When you query TaskWhoRelation, it only retrieves the primary contact, rather than all of the related Contacts. I’m trying to update Contacts with the latest open Task date, based on TaskWhoRelation. But I’m starting to think this is impossible with current unresolved bugs (since Winter ’13 no less!).
LikeLiked by 1 person
Hi, no I have not tried this yet with the Shared Contacts relationship, just the standard WhoId field. That known issue sounds like a real bugger, thanks for bringing it to our attention so we can follow it too for updates from Salesforce.
LikeLike
I’ve recently blogged about how to support “Shared Contacts”,
https://douglascayers.com/2016/12/26/how-to-update-leads-or-contacts-when-shared-activities-logged/
Hope this helps!
LikeLike
Hey Doug,
Like what you’ve done here!
I’m running into an issue; I set the “WhoID is Lead” part, but it’s when I get to the “Immediate Actions” and try to “Update Record” with the “Set Lead ID”, however since I am picking “Task”, “Select the task record that started your process”, I am unable to click the “Lead” for the field. Any ideas?
Thanks!
LikeLiked by 1 person
Hi Ross,
There will be two processes that you create, and I suspect you might be trying to update the Lead in the first process rather than athe second.
The breakdown is:
First process is to take the generic WhoId field value and copy it into another lookup field, either a Lead lookup field or a Contact lookup field. That is this first process’ entire purpose in life. Copy the polymorphic WhoId value into a deterministic lookup field. Only the Task that started the process will be updated in this first process.
Second process also monitors for edits being made on the Task record but it specifically monitors when the deterministic Lead (or Contact) custom lookup fields have changed and are no longer blank. It is in this second process that you will be able to add an immediate action of “Update Records” then choose a record related to the Task by choosing “Lead” (or whatever you labeled your Lead lookup field to be when you added it as custom activity field).
Hope that helps!
Doug
LikeLike
I am able to complete the “WhoID is Lead” part and assign it as the “00Q”, however it’s when I get to the “Update Records” section and choose “Record Type” as “[Task]”, I am unable to pick “Lead” as my “Field” type and assign the value of “[Task.WhoID]”, as referenced in your picture above.
LikeLiked by 1 person
Please share some screenshots of your configuration. Will make troubleshooting easier. Thanks!
LikeLike
Hey Doug,
Link below. I am unable to find “Lead” in the “Field” option, as it is being related to the “Record” of the Task.
I am trying to get the Lead Status to be updated based off a completed task.
Thanks!!
LikeLike
Hi Ross,
Did we ever resolve the issue for you? I apologize if I’ve missed your comment update all these past weeks!!
Let me know if you’re still having issues and want some help.
Thanks,
Doug
LikeLike
I had to read it a couple of times but it worked out great for me. Thanks for putting this together.
LikeLiked by 1 person
Thanks, Mig for the kind feedback!
Were there any parts that you think I could explain better?
Thanks!
LikeLike
Ha! This is genius. Thanks!
LikeLiked by 1 person
Thanks Scott!
LikeLike
Hello Doug,
Thank you for the post it has been very helful! I am having trouble when I am trying to update all the contacts related to a task that has many contacts related to it. What I have done so far is just updating what is classified as the primary contact and nothing else.
Do you have any suggestions or thoughts about this?
LikeLiked by 1 person
Hi Elias,
Thanks for the kind feedback! Yes, I believe you will need to have Process Builder invoke a Flow so that you can query the TaskWhoRelation object to learn about all the other Contact or Lead IDs associated with your Task. From there, you’d loop through the sobject collection of relation records then do any Updates or Lookups as needed on the Contacts.
I’m working on a new blog post that will show exactly how to put this solution together.
Doug
LikeLike
Thank you Doug for your reply and for working on this solution!
LikeLiked by 1 person
Hi Elias,
Finally had some time to dig into supporting Shared Activities. It was not exactly as straight forward as I had hoped due to a Flow limitation and TaskRelation records being created by Salesforce asynchronously from the Task itself.
I’ve just blogged about the solution here: https://douglascayers.com/2016/12/26/how-to-update-leads-or-contacts-when-shared-activities-logged/
Hope this helps!
Doug
LikeLike
Hi Doug!
Thanks for your help–I Tweeted you last night. It worked perfectly…when a user logs at task inside the org.
However, as I quickly realized this morning, my users sometimes complete tasks external to our org. They use something called Tout App which logs Emails as closed tasks on the relevant record. When I user did this, I realized my lead status had not been updated! Eek!
I fixed this by going into Process Builder and adding one more requirement, Task Type = Email and that seemed to fix it. Screen shot here: http://imgur.com/a/PsIsw
Would you recommend a different solution?
Cynthia
LikeLiked by 1 person
Hi Cynthia,
Thanks for the kind feedback! According to your screen shot, your process builder criteria would fire if the WhoId is a Lead or the Type is Email. I’m assuming that’s because the Tout App logs emails but is not setting Who the email is for?
When you view the Tout App logged task, is the Who field populated? If yes, is it a Lead or a Contact?
When is your process configured to run – on create only or whenever it’s created or edited?
Thanks,
Doug
LikeLike
Hi Doug,
I have been using this process for a few days and it has been working very well. We are using it to update a custom field on the Lead/Contact with the Last Activity Type/Result/Date, which is very useful for generating certain reports.
However, we have been getting errors when certain (not all) leads are being converted to contacts. Because of the error, I broke it up into 2 processes, one for leads, and one for contacts, in order to narrow down the issue. Apparently the Contact Process is causing the problem during conversion.
Here is a sample error:
An error occurred at element myRule_1_A1 (FlowRecordUpdate).
UPDATE — UPDATE FAILED — ERRORS : (ALL_OR_NONE_OPERATION_ROLLED_BACK) Record rolled back because not all records were valid and the request was using AllOrNone header — for SFDC record with ID : 003j000001Nhmc0AAB
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Contact_Last_task_Update
Type: Workflow
Version: 2
Status: Active
Flow Interview Details
Interview Label: Contact_Last_task_Update-2_Task
Current User: Test User (005j000000A1ABC)
Start time: 12/20/2016 10:32 AM
Duration: 1 seconds
How the Interview Started
Test User (005j000000A1ABC) started the flow interview.
Some of this flow’s variables were set when the interview started.
myVariable_old = 00Tj000000waaGxDEF
myVariable_current = 00Tj000000waaGxDEF
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = “12/20/2016 10:32 AM”
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.WhoId} (003j000001Nhmc0AAB) Starts with 003
2. {!myVariable_current.IsClosed} (true) Equals true
Logic: All conditions must be true (AND)
RECORD UPDATE: myRule_1_A1
Find all Contact records where:
Id Equals {!myVariable_current.WhoId} (003j000001Nhmc0AAB)
Update the records’ field values.
Last_Activity_Result_Date__c = {!formula_2_myRule_1_A1_Last_Activity_Result_Date_c} (Call Out – NLM – 7/25/2016)
Result
Failed to update records that meet the filter criteria.
Any idea where the problem might be?
Thanks!
Jeremy
LikeLiked by 1 person
Hi Jeremy,
Glad this solution is working for you all!
The exception message at the top of the error email says “Record rolled back because not all records were valid”. My first guess is that a validation rule might be rejecting some data.
Do you receive a 2nd error email with any other details about what went wrong? As-is, the error you’re receiving is that something about the Contact being updated didn’t jive with what Salesforce expected.
Thanks,
Doug
LikeLike
Doug,
I thought we had this figured out after updating the PB to “execute the actions only when specified changes are made to the record.” We had no errors in last 2 weeks, albeit with less work being done over the holidays). And then last night someone converted a lead and we had the errors again. Here is the error that showed up on the conversion screen:
Error: System.DmlException: Update failed. First exception on row 0 with id 00Tj000000zm9pBEAQ; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301j00000004kZk. Flow error messages: An unhandled fault has occurred in this flowAn unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: [] Class.leadconvert.BulkLeadConvert.updateLeadTasks: line 1279, column 1 Class.leadconvert.BulkLeadConvert.convertLead: line 127, column 1
The contact record doesn’t have any validation rules or required fields (that are missing data), so I don’t believe that is the issue.
LikeLiked by 1 person
Hi Jeremy,
Hrm… that error looks like an Apex Exception email when the trigger class leadconvert.BulkLeadConvert executed the method convertLead at line 127. That class is using the namespace “leadconvert” so likely part of a managed package? If yes then we may not be able to dig into what the code is doing.
But, since the Process Builder failed I think you (or the person who last activated the process) should have received an email with all the details about what Process Builder was doing leading up to the error. Could you share those details please?
Thanks,
Doug
LikeLike
here is the email I received. I have selected only on of the tasks that was included in the error. There seems to be an error listed for every task that existed on the Lead when it was being converted.
Error Occurred: UPDATE — UPDATE FAILED — ERRORS : (ALL_OR_NONE_OPERATION_ROLLED_BACK) Record rolled back because not all records were valid and the request was using AllOrNone header — for SFDC record with ID : 003j000001OadHfAAJ
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Last_Activity_Field_Update_Contacts_Only
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Last_Activity_Field_Update_Contacts_Only-1_Task
Current User: John Smith (005j0000000TY7S)
Start time: 1/3/2017 6:05 PM
Duration: 1 seconds
How the Interview Started
John Smith (005j0000000TY7S) started the flow interview.
Some of this flow’s variables were set when the interview started.
myVariable_old = 00Tj000000zm9pBEAQ
myVariable_current = 00Tj000000zm9pBEAQ
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = “1/3/2017 6:05 PM”
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.WhoId} (003j000001OadHfAAJ) Starts with 003
2. {!myVariable_current.IsClosed} (true) Equals true
Logic: All conditions must be true (AND)
DECISION: myRule_1_pmetdec
RECORD UPDATE: myRule_1_A1
Find all Contact records where:
Id Equals {!myVariable_current.WhoId} (003j000001OadHfAAJ)
Update the records’ field values.
Last_Activity_Result_Date__c = {!formula_2_myRule_1_A1_Last_Activity_Result_Date_c} (Call Out – SPK – 10/5/2011)
Result
Failed to update records that meet the filter criteria.
LikeLiked by 1 person
Thanks, this definitely is a strange one to work out. The most specific error message I’m gleaning from this is “Failed to update records that meet the filter criteria.” — which isn’t very specific.
Question, what is the order of operations between the lead being converted and the task running through this process? Does the lead convert code create the task?
Maybe it’s a timing issue.. perhaps in your Process Builder move your action from the “Immediate Actions” to the “Scheduled Actions” and have it run 0 hours after LastModifiedDate. That should make the process builder logic run, typically, within a few minutes.
LikeLike
The tasks already exist on the lead, and salesforce just attaches the old tasks to the new contact. I have just updated the PB to run only when a task is created, not when edited. I’ll try your suggestion, but I’ll have to wait and see if it resolves the issue. I have not been able to reproduce the issue on demand.
LikeLiked by 1 person
I made the change to the Scheduled Actions. Interestingly, I got an error email this morning, but the lead conversion was successful. So other than the annoying email, the process seems to be working.
Here is a copy of the error:
An error occurred at element myWaitEvent_myWait_myRule_1_event_0_SA1 (FlowRecordUpdate).
UPDATE — UPDATE FAILED — ERRORS : (ALL_OR_NONE_OPERATION_ROLLED_BACK) Record rolled back because not all records were valid and the request was using AllOrNone header — for SFDC record with ID : 003j000001PcMX0AAN
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Last_Activity_Field_Update_Contacts_Only
Type: Workflow
Version: 2
Status: Active
Flow Interview Details
Interview Label: Last_Activity_Field_Update_Contacts_Only-2_Task
Current User: John Smith (005j000000DzDRd)
Start time: 1/5/2017 9:16 AM
Duration: 114 seconds
How the Interview Started
John Smith (005j000000DzDRd) started the flow interview.
Some of this flow’s variables were set when the interview started.
myVariable_old = 00Tj000000zmRx2EAE
myVariable_current = 00Tj000000zmRx2EAE
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = “1/5/2017 9:16 AM”
DECISION: myPreWaitDecision_myWait_myRule_1
Executed this outcome: myPreWaitRule_myWait_myRule_1
Outcome conditions: and
1. {!myVariable_current.WhoId} (003j000001PcMX0AAN) Starts with 003
2. {!myVariable_current.IsClosed} (true) Equals true
Logic: All conditions must be true (AND)
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.WhoId} (003j000001PcMX0AAN) Starts with 003
2. {!myVariable_current.IsClosed} (true) Equals true
Logic: All conditions must be true (AND)
DECISION: myRule_1_pmetdec
WAIT: myWait_myRule_1
The waiting conditions for the following wait events were met.
Wait Event: myWaitEvent_myWait_myRule_1_event_0
Waiting Conditions:
1. {!myWaitEvent_myWait_myRule_1_event_0_postActionExecutionVariable} (false) Equals false
Logic: All conditions must be true (AND)
Event Type: Alarm: Relative Time
Object Type = Task
Record ID = {!myVariable_current.Id} (00Tj000000zmRx2EAE)
Offset Unit = Hours
Offset Number = 0
Base Date/Time Field = LastModifiedDate
Result
Started waiting at 1/5/2017 9:16 AM.
The interview started waiting at 1/5/2017 9:16 AM.
The interview was resumed at 1/5/2017 9:17 AM by John Smith (005j000000DzDRd).
WAIT: myWait_myRule_1
Wait event myWaitEvent_myWait_myRule_1_event_0 occurred.
The following values from the event were assigned to flow variables.
None.
DECISION: myPostWaitDecision_myWaitEvent_myWait_myRule_1_event_0
Executed this outcome: myPostWaitRule_myWaitEvent_myWait_myRule_1_event_0
Outcome conditions: and
1. {!myVariable_current.LastModifiedDate} (1/5/2017 9:16 AM) Is null false
Logic: All conditions must be true (AND)
RECORD UPDATE: myWaitEvent_myWait_myRule_1_event_0_SA1
Find all Contact records where:
Id Equals {!myVariable_current.WhoId} (003j000001PcMX0AAN)
Update the records’ field values.
Last_Activity_Result_Date__c = {!formula_2_myWaitEvent_myWait_myRule_1_event_0_SA1_Last_Activity_Result_Date_c} (Call Out – Info Requested – 11/4/2014)
Result
Failed to update records that meet the filter criteria.
LikeLiked by 1 person
Question, on your Contact object do you have any lookup fields that have lookup filters on them? Specifically, does the record 003j000001PcMX0AAN have values in any lookup fields that no longer satisfy lookup filters?
Same question for that contact’s parent account. Does the Account object have any lookup fields that have lookup filters on them?
When the contact 003j000001PcMX0AAN is updated, are there any other triggers that might be running to do rollups or some other update?
What about the Last_Activity_Result_Date__c field. Have we already checked that it’s length is long enough to hold “(Call Out – Info Requested – 11/4/2014)”? Is this a TEXT or PICKLIST field? If PICKLIST, is it “restricted” and perhaps the value inputted is invalid?
LikeLike
By moving your Update Records action from “Immediate” to “Scheduled” all that has done for us is allow the conversions to occur. So it at least removes that roadblock to your users until we identify what’s causing the update on the contact to fail. Once that is identified and fixed then you’d be able to move it back to an “Immediate” action (if you want everything to be all or nothing).
LikeLike
Doug,
Do you happen to know if it is still not possible to update a field on a Task with data from a Lead, such as the State? Either through Process builder when a task is created, or with a formula field on a task. I have heard that it’s possible with an Apex trigger, but I;ve never written one and not sure where to begin.
Thanks,
Jeremy
LikeLiked by 1 person
Hi Jeremy,
If you just need to expose more data from the Lead or Contact the Task is related to then I’d take this approach:
#1 Create custom Lead and custom Contact lookup fields on your Task object
#2 Using same technique in this blog post, when a Task is being created or updated look at the WhoId and if starts with “003” then copy the [Task].WhoId into the [Task].Contact__c lookup field. If “00Q” then copy the [Task].WhoId into the [Task].Lead__c lookup field.
#3 Create formula fields on Task object that expose data from the Lead or Contact lookup fields depending on which is not empty.
For example, to expose the State might have formula field like: IF( ISBLANK( Contact__c ), Lead.State, Contact.MailingState )
If the Lead’s Contact lookup field is populated then the formula will display the state from the contact, else the state from the lead if that lookup is not blank.
No triggers. Just process builder + custom lookup fields + formula fields.
Hope that helps,
Doug
LikeLike
Doug,
This is awesome! Just implemented it and have put some key information onto the Task as well as an Activity List. Sales reps are already super excited!
There are a lot of posts out there saying that this can’t be done – is this functionality new?
Thanks!
Jeremy
LikeLiked by 1 person
Great to hear! Glad it’s working out for you all.
Well, this trick to use custom lookup fields on Task object is possible as of Winter ’16 release.
But this could have been done without code well before then by using Process Builder and Flow. The Flow could have done a Fast Lookup to get all Tasks whose WhoId equals the Lead or Contact ID passed to it and update all the tasks if desired. Once you get thousands of tasks then it needs to refactor into batchable apex to stay within governor limits.
But this is definitely doable without a “code first” solution.
Could you share the posts that are saying this can’t be done?
Thanks,
Doug
LikeLike
Here are a few that came up via some Google searching. They either mention the lack of ability, or imply that only a trigger can do it.
This one seems to just say no, and it comes up prominently when searching, although it is 4+ years old: https://success.salesforce.com/answers?id=90630000000h2VTAAY
And some others that imply that a trigger is needed:
https://developer.salesforce.com/forums/?id=906F00000009iboIAA
https://developer.salesforce.com/forums/?id=906F0000000D8klIAC
https://success.salesforce.com/answers?id=90630000000CxesAAC
At least your post comes up with most of the related searches!
LikeLiked by 1 person
Hi Doug this is a really great tutorial. I have followed the instructions to create the processes so that anytime there is a closed task performed against a Lead, we change the Lead Status from “New” to “Working”, which is great!
However, if I only want to stop this process from triggering if the Lead has a different status – like “Qualified”, how would I do that?
LikeLiked by 1 person
Hi Tim,
Great question!
In your Immediate Action which is performing the field update on the Lead record, just above where you’re assigning the field values is a section labeled “Criteria for Updating Records”. You can specify criteria there to narrow down which Leads you actually want the update to apply to.
For example, in the video I don’t specify any criteria so the option chosen at about this time in the video is “No criteria – just update the records!”. But you can change that to “Updated records meet all conditions” and add a condition where the Status field does not equal “Qualified” (or any mix of desired criteria).
Hope that helps!
Doug
LikeLike
Doug – this is huge! I’m a big fan of your blog because it really dives into the details of what salesforce admins need to do, and it’s relevant.
Thank you for your help. I’ve been trying to get previous teams I’ve worked with to implement this change and I’m impressed how fast I got this done, ONLY through your assistance.
Thank you again and I’ll be revisiting your blog for sure.
Tim
LikeLiked by 1 person
Glad to help, Tim! Thanks for the kind feedback, made my day =)
LikeLike
You are a hero to the people! I’ve been trying to solve this for a week!
LikeLiked by 1 person
Ha! Thanks for the compliment Heidi =)
LikeLike
New solution available here: https://douglascayers.com/2017/04/02/use-process-builder-to-update-related-records-when-activities-logged
Comments are now disabled on this archived post.
Thanks!
LikeLike