This has been an ambiguous field for many Salesforce Customers, Developers and Admins alike since ages and till date people are ambiguous about what value exactly goes into the LastActivityDate in the Account object. The most common misconception is that LastActivityDate holds the date when the last activity record associated to the account was added/modified. However, the reality is far different. The field actually holds either of the below values.
- Due date of the most recent event logged against the record.
- Due date of the most recently closed task associated with the record.
This is where people call the field deceptive. However, if we didn’t know this then it’s because we as human beings tend to assume things and Salesforce has clearly mentioned in their documentation about what value goes into their respective fields in the schema and the reality here is that we just never bothered to look at it. Below is the link to a knowledge article from Salesforce which explains the difference between the Last Activity and Last Modified.
I have burned my hands in the past when dealing with this field and thought of sharing this so that at least someone who has read this post doesn’t fall into the same deathtrap !
So now let’s see how do we figure out to build a field which will actually hold the value that you were looking for – the date when the last activity record was added to an Account. It’s actually a cakewalk to do this using the Process Builder. Well, it wasn’t this easy sometime back to build the same stuff wherein you had to use a combination of process builder and flows if you wanted to fetch the Last Date when an activity record was added to any of the objects (Custom or Standard). We no longer have to go down the path of flows to do this, all thanks to Salesforce for coming up with an improved version of process builder with every new release (Yeah, it keeps getting stronger). Now, let’s get down to the implementation part. The approach mentioned here can be followed for any of the objects in Salesforce, be it Custom or Standard with the exception of Contacts and Leads.
Steps
Create a custom datetime field on the Account called as LastActivityLoggedOn. A datetime field is more preferable over a date field, because it even allows us to capture the time when the activity was logged which becomes crucial for many businesses.
Go to Setup > Process Builder and set up the process as seen in the screenshot below
The process I have configured here is to capture the time when the activity was added and not when it was modified. If you want to capture the time when the associated activity record was last modified, then you need to select the second checkbox in the below screenshot.
The next step is to select a criteria for the process. However, we simply want to capture all the activity records that are added, so the process won’t have any criteria !
The action for the process can be configured as seen below
Simply select the Related to ID (Account) in the object to be updated.
Finally the LastActivityLoggedOn field can be assigned a formula value of NOW() as seen below.
That’s it. Simply Activate your workflow and you are good to go. Henceforth as and when a new activity record is added to Account, the LastActivityLoggedOn field would be populated with the appropriate value.
Feel free to comment on this post if you have any question or issues.
Hi Akhil.
You indicate the following:
Due date of the most recent event logged against the record.
Due date of the most recently closed task associated with the record.
However, this would imply that if I log an event for an account with a due date of today, then say “Oops, I forgot to record yesterday’s event”, and add that one, then a report should show a date of yesterday as the “last activity”, since the due date of the newest created event is yesterday. However, when I test this in Salesforce, it doesn’t bear out. It keeps the literally most recent due date. Is there some other logic Salesforce has going behind the scenes that involves something other than just the due date?
LikeLike
Hi Dayna,
The results you have got are indeed expected. Salesforce doesn’t really care when the record was added to the account and that’s why I called it “Deceptive”. LastActivityDate will always be populated with (literally) the most recent date of all the activity records tagged to the account.
I hope that solves your confusion ?
Regards,
Akhil Anil
LikeLike
Hi Dayna,
The results you have got are indeed expected. Salesforce doesn’t really care when the record was added to the account and that’s why I called it “Deceptive”. LastActivityDate will always be populated with (literally) the most recent date of all the activity records tagged to the account.
I hope that solves your confusion ?
Regards,
Akhil Anil
LikeLike
Yes, thanks. It almost sounds like they use the creation date of the record or something in their “behind-the-scenes” formula.
LikeLike
Thank you for the detailed info!
LikeLike
nice job. Just implemented this and it works as designed. we use this on the Lead Object, not the account and it works just the same. We have a third party app creating events (autopilot email sends/ opens) which makes it difficult to distinguish between a real ‘call’ and an automated event. With this process-builder updated field we can track the real sales call versus an automated event. Thank you for your time putting this together so nicely.
LikeLike
This is very useful. I would like to log the “real” last Activity date of either a Task or an Event…do you think I should create a second process for “Event” and have a second Date/Time field on the Account to register the Event also?
LikeLike
Hi Akhil,
Does this same logic apply to the LastActivity field on Opportunities, Contacts, and Leads as well? I’m wondering if I should set up a similar process for those objects.
Thanks,
Brian
LikeLike