Updating Records from Activities & Creating a Contact Scoring Model

Activities, Tasks, and Events are one of the more unusual objects in Salesforce.  With low limits on custom fields, strange polymorphic lookups, and other oddities, working with Tasks & Events can be tricky.

One of the more common challenges users experience is updating related records from a Task or Event.  Once you master this skill, you can use this ability to build more advanced customizations, like a Contact Scoring feature to supplement marketing automation programs like Hubspot.

To get started, these are the two most common types of questions I encounter in the Trailblazer community related to Activities (Tasks & Events).

1: ‘How can I update a record from a task?’

2: ‘When a task is created (or completed) I try to update a field on the related record but get a ‘…..not set or assigned error.” How can I update this record?

Updating a Record from a Task or Event

The trick in updating a Task or Event is to understand the polymorphic WhatID and WhoID.

WhoID is the Name field, which identifies the Lead or Contact

WhatID is the Related To field, which identifies the object the activity is related to.

These are known as polymorphic fields because they are one of the few lookups in Salesforce that can lookup to multiple objects.

The key to updating the related WhoID record or WhatId record is knowing the object id prefixes in Salesforce.  A full list can be found here.  Some one common ones are Lead,’00Q’; Contact, ‘003’; Account, ‘001’; and Opportunity,’006.’

Now, to update the related WhoID or WhatID, you’ll need to use process builder.  Start your Process Builder on either the Task or Event Object depending on your needs.  In your criteria, specify that the Name field (WhoID) or Related To field (WhatID) starts with the proper prefix, in this case I want to update a contact record, so I enter ‘003.’  You can also add additional criteria, like specifying the subject, type, or other values to meet your business needs.

For your immediate action, select Update Records, and either the correct Name or Related To you identified in your criteria.  Now you can update the values on that record to meet your business requirements.  Activate your process and you are good to go!

Updating a Record from a Task or Event when Referencing a Field on the Related Record

There is a caveat to the above process though, which results in the aforementioned ‘not set or assigned error.’  Let’s say that instead of populating a date field, I wanted to increment a call count field by 1.

While this formula will save and the process activate without any errors, when you attempt to create a task on the contact object, the process will fail and send an error message like ‘The flow failed to access the value for myVariable_current.WhoId.Call_Count__c because it hasn’t been set or assigned.’ 

This is one of the limitations of the polymorphic, we are unable to introduce the Contact object and its field into the flow interview through our criteria, so we cannot update a Contact field with a formula that references a Contact field.

To solve this, we have to create two process builders.  The first one we’ve already created, that is to update a field on the contact record with a value of Today(). The second one will start on the target object, in this example, the Contact object.  For our criteria, we’ll use the field that was updated in the previous process builder, so this next process will fire when Last Contact Date equals Today().  Be sure to check the box under advanced, so this process builder will only fire once.

The next step is to define our field update on the Contact record.  You’ll notice I used an IF() function, so that if my count field is null, it is defined as 1, otherwise the field is incremented by 1; this will prevent an null related error when the process fires.

Save the process, activate and when a task is created, our first process builder will populate the target Contact field with today’s date, which causes the next process builder to fire and update the Contact record’s target field.

Building a Contact Scoring Model with Process Builder

Many marketing automation programs have great lead scoring features to help a business identify who is engaging the most with their company, however they lack the same features for contacts.

Using the two process builders above, you can build a very robust Contact Scoring solution.

First, you’ll need to build a ‘Last X Date’ and ‘X Count’ field for each activity you want to track.  For this example, lets imagine we are running a special campaign to existing customers promoting a new product and we want to track specific email opens and clickthroughs.  This campaign will use emails with a campaign specific subject line, which is sent to Salesforce by our marketing automation tool as a Task with the email subject as the Task subject.

Process Builder 1: Task Object

Using the same basic setup as our first process builder above, you’ll define a set of criteria and a field update for each activity you want to track.

For your subject line, you would define the string you want to flag, such as ‘New Product Email Opened’ or ‘New Product Email Clicked,’ you will need to review how your marketing automation program is sending those tasks to Salesforce to set these values.

For each set of criteria, you’ll create a field update for the corresponding ‘Last X Date’ field on the target object.  In this example, our first criteria would have a field update that populates Contact.LastEmailOpenedDate with a value of Today() and the second criteria would populate the Contact.LastEmailClickedDate with a value of Today().

The next process builder would similarly evaluate when ‘Last X Date’ field equals today to increment another field.  In this example we would update Email Opened Count and Email Clicked Count by 1, when LastEmailOpenedDate=Today() and LastEmailClickedDate=Today(), respectively.

To create a single contact scoring metric, we would simply use a formula field like below, where each activity is awarded a certain amount of points:



This process builder, just like your lead scoring metrics, will need to be maintained regularly to stay relevant. I have built out this same feature with 20+ task subject lines and 20+ count fields on the contact record and it works well.

As campaigns and targeted subject lines change, new fields need to be created and the Process Builders updated, so it is a consideration before implementing.

A benefit of this approach versus say, using Declarative Lookup Rollup Summaries to count tasks, is the ability to reset your scores.  You can use data loader to reset all ‘x Count’ fields to 0 or use a PB to set them all to 0 when specific values change on the account or contact.

While DLRS is great for counting total tasks, finding a max date from tasks, and other builds, for a larger effort like a Contact Scoring model, this approach would require less maintenance over time.


  1. Brandon Eccles says:

    Hi Tom,

    First off, thanks so much. This is awesome! I love this post. I was hoping you could help me with something similar that I’m struggling with. I would like to have a custom number field on the lead object updated by related tasks. The custom field is ‘# of Open Activities’.

    I have my custom field counting correctly but, because of the complexity of the polymorphic fields, I don’t know how to get that counter to decrease by 1 when the task is completed.

    Any idea on how to accomplish this?

    Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *