A sales manager wants to know when their team last contacted each customer. They need a field that displays the most recent activity, such as a call, meeting, or email, on the account.
This helps them quickly find which customers have not been contacted recently and take follow-up action. I was assigned the task of tracking the last time an object record was modified or created and displaying it.
In this Salesforce tutorial, we will learn the Salesforce Last Activity Date Formula. Additionally, we will review how to use Salesforce to create the ‘Last Activity Date’ formula field.
Salesforce Last Activity Date Formula
In Salesforce, we can generally perform two types of activities on any object, such as creating a record and modifying an existing record. So, for the last activity date formula, we only need to track the last time a record was modified or created.
To create this formula, we utilized only two predefined fields,ย LastModifiedDate and CreatedDate,ย of any Salesforce object. And in return, the formula field displays the last modified or creation date and time of the record.
Now, let’s see two different formulas to calculate the last activity date in Salesforce. In the next section, we will learn to use these formulas in Salesforce.
Formula #1
IF(LastModifiedById <> null, LastModifiedDate,
IF(CreatedById <> null, CreatedDate, null)
)
- In this formula, we first check that the LastModifiedById field is not null. If it is, we return the LastModifiedDate.
- Otherwise, the formula checks that the CreatedById field is not null. If it is, we return the CreatedDate.
- If both the fields LastModifiedById and CreatedById are null, we return null.
Note: If the CreateById and LastModifiedById fields are not null, it means the record has been created and modified at least once.
Formula #2
IF(
NOT(ISBLANK(LastModifiedDate)),
LastModifiedDate,
IF(
NOT(ISBLANK(CreatedDate)),
CreatedDate,
null
)
)
- In this formula, we first check whether theย LastModifiedDateย andย CreatedDateย fields are blankย using the ISBLANK function.
- If LastModifiedDate is not blank, the formula returns the value for LastModifiedDate. Otherwise, it checks that the CreatedDate field is not blank. The formula returns the value for CreatedDate.
- If both the fields are blank, the formula returns null.
You can use either of the above-defined formulas. They both work in similar ways.
With this, we now know about the Salesforce Last Activity Date Formula. Next, we will proceed to learn howย to calculate the Last Activity Date formula field in Salesforce Lightning.
Last Activity Date Formula Field in Salesforce Lightning
Here are the steps to define the Salesforce last activity date formula field in Salesforce Lightning.
- Click theย Setupย icon in the top right corner of the page to access Salesforce Setup.
- Clickย Object Managerย from the menuโs left side.

- Look for the item to which we want toย determine the last activity date. In this example, I choose theย Contactย object from the list of objects.

- Chooseย Fields & Relationships. Next, selectย New.

- Select “Formula”ย as the field type. Clickย Nextย to proceed.

- After entering aย Field Labelย for the formula, theย Field Nameย will be filled in automatically. Here, I enter Field Label as the Last Activity Date.
- Selectย Dateย as the Formula Return Type. After that, clickย Next.

- Enter the formula that calculates the last activity date in the Advanced Formula editor. The formula is given below:
IF(
NOT(ISBLANK(LastModifiedDate)),
LastModifiedDate,
IF(
NOT(ISBLANK(CreatedDate)),
CreatedDate,
null
)
)
- To verify that the formula is valid, clickย Check Syntax.
- We can specifyย how you want to handle the empty fieldย and include the Descriptionย andย Help Textย as alternatives.
- Then, selectย Next.

- Select the appropriateย Field Level Security,ย and to make it visible to everyone, we select theย Visibleย checkbox. Selectย Next.

- Select theย Page Layoutย Name for which the formula field is to be added. Clickย Saveย to save the formula field.

- We can use the formula field once it has been created. Letโs look at an example:
- Create a new contact or open an existing one by navigating to theย Contactsย item and saving the contact.
- After that, click on theย Detailsย section, and here the Last Activity Date field appears, which shows the created or last modified date of the record.


As a result, we now know how to useย Salesforce Lightningโs advanced formula to calculate the last activity date.
Conclusion
With this, we have learned the Salesforce Last Activity Date Formula. Moreover, we have learned the simple procedure for determining the last activity date in Salesforce Lightning.
You may also like the following Salesforce tutorials:
- Salesforce Date Range Formula
- Use Date Formula in Salesforce Report
- Salesforce Date Formula Business Days
- Salesforce Formula Date Greater Than Today
- Salesforce Formula Date Less Than Today
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.