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.