Last Updated on April 11, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How to keep track of the last activity date and show it on the object detail page?
After reading this blog, you’ll be able to:
- Understand the differences between Last Activity and LastModified Dates
- Understand how Salesforce calculates the LastActivity Date
- Create a formula field to show the last activity date on standard and custom objects
- and much more
Business Use case
Anita Smith is working as a Salesforce Consultant at Gurukul On Cloud (GoC). She has received the following requirement from her Sales director to display ‘Last Activity Date‘ on the Opportunity record detail page.
Guided Practice (We-do):
In Salesforce, we use activities to keep track of all customer interactions. For example, you can send emails, make phone calls, set up appointments, and delegate tasks. We often come across the requirement to show the last activity date for an account, lead, contact, opportunity, or custom object.
Without the Last Activity Date Tracker, you need to go through all your activities manually to determine your most recent touchpoints and contact types for an account or contact. This method is time-consuming, frustrating, and prone to error.
Differences between LastActivity and LastModified Dates
First and foremost, Last Modified and Last Activity are not the same.
- The LastModified represents the date and timestamp for changes made to an individual record, including the User who made the change.
- The LastActivity represents the date and time stamp for changes (for example, changes to an email, or Annual Income) made to a lead. By default, this field is not available in page layout but is available in Report, List View, and API (including Formula Field and Validation Rule) for Account, Contact, Opportunity, Lead, and custom objects.
- It represents one of the following:
- The most recently Completed Task is associated with the record.
- The Due Date of the recently logged Event against the record.
- It represents one of the following:
How the Last Activity Date is Calculated?
A single Task and event may be associated with one or more records. For example, an event can be related to an Account and Contact(s) or a Contact and a Case.
The activity record has an account_id field that is different from the what_id and who_id fields. The value of LastActivity on Account is calculated by introspecting the who and the what, with the what taking precedence. For example, when a user logs a call to a Contact, the Last Activity on the Account will be updated.
Perform the steps below to create a custom field to show the Last Activity Date:
- Click Setup.
- In the Object Manager, type Opportunity and select Opportunity.
- Select Field & Relationship, then click New.
- Select Formula as Data Type, then clicks Next.
- Choose output Type
- Enter the formula:
- Set the Field-level Security for the profiles, make sure to set this field as read-write.
- Add this field to Page Layout.
- Click Save.
Points to Remember
- The last activity date for an account record is based on all the activities that roll up to the account via the Related To field. For an account, the last activity date can represent an activity that’s related to an opportunity. The last activity date for a contact or lead is based on all the activities that are related to that contact or lead via the Name field.
- If Shared Activities is enabled, an account’s last activity date is still based on the activities that roll up to the account via the Related To field. But if the Related To field is blank, the activities are based on the primary contact’s account. The last activity date for contacts and leads is based on only the activities where the contact or lead is the primary contact in the activity.
- The LastActivityDate is only available if the Allow Activities checkbox under Optional Features is enabled in the custom object’s setup page. If it is not checked, this system field will not be available through the API or in reporting.
- Rule to find what
- The “what” is an account: The account_id is that account.
- The “what” is an opportunity: The account_id is the account associated with that opportunity.
- The “what” is a contract: The account_id is the account associated with that contract.
- The “what” is a Custom object that is parented under an account: The account_id is the account associated with that custom object.
- If the “account_id” cannot be derived from the “what” using the rules above, then we look to the “who.” If the “who” is a contact with an associated account, then the “account_id” is the account associated with that Contact.
- The field is not available for all Objects, For example, LastActivity is not available on the Case object.
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
11 thoughts on “Display Last Activity Date on Object Record Detail Page”
Will it be possible to exclude the emails sent by Pardot/Account Engagement? This is affecting the true ‘last activity’ which would be made by a sales person.
You have to consider building a custom LastActivityDate field
Good morning Rakesh, I am not sure that I understand the article you refrenced, and think that my settings are correct, when I send an email wither from outlook on my desktop for mac, or when I send an email from Salesforce, neither action is recorded as a Last Activity? Any suggestions as to what may not be set correctly? ( The emails do show up in the contacts and accounts activity field in sales force)
As always thank you.
I am not sure Mario. Check this help article Last Activity not updated for all Contact records after using Outlook and Gmail Integration’s Log Email Action
HI RAKESH, I am not seeing that an email is triggering the last activity function? I must not have a setting set correctly?
Email log via Outlook or an outbound email?
Ok. Fantastic. That worked.
So then I will ask, can this also track email? Email for me is also considered a form of contact or activity? So now it will track all activities I log as tasks which is good and just wondering if it will track emails. Thank you so much for sharing your knowledge.
Yes, but make sure to read this help article Last Activity not updated for all Contact records after using Outlook and Gmail Integration’s Log Email Action
Hi I followed your outline as noted above and was able to see that I now have ‘Last Activity’ field (I put it on my contacts page as I would like to see last activity for contacts) The field is present and visible however it is not populating?
Display Last Activity Date on Object Record Detail Page
Add and complete a Task. The Last Activity field will now show the date from the completed Task.