In this Salesforce tutorial, we will learn the **Salesforce Last Activity Date Formula**. Additionally, we will go over how to use Salesforce Lightning and Salesforce Classic to create the last activity date formula field.

While working for an organization that uses Salesforce, I was assigned a job to track the last time an object record was modified or created and display it.

So, to fulfill this requirement, I define an advanced formula that calculates the last activity date. If you want to learn how to create a custom last activity date formula field, you have come to the right place.

The following are the topics that we will cover in this salesforce tutorial:

- Salesforce Last Activity Date Formula
- Last Activity Date Formula Field in Salesforce Lightning
- Last Activity Date Formula Field in Salesforce Classic

## Salesforce Last Activity Date Formula

In Salesforce, generally, we can perform two kinds of activities on any object such as creating a record and modifying a record. So, for the last activity date formula, we only need to track the last time a record was modified or created.

And, to create this formula, we utilized only two pre-defined 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 Lightning and Salesforce Classic.

**Formula #1**

```
IF(LastModifiedById <> null, LastModifiedDate,
IF(CreatedById <> null, CreatedDate, null)
)
```

- In this formula, we first check the
**LastModifiedById**field is not null. If it is, we return the**LastModifiedDate**. - Otherwise, the formula checks the
**CreatedById**field is not null. If it is, we return the**CreatedDate**. - If both the field
**LastModifiedById**and**CreatedById**are null, we return null.

**Note: **If **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 that the
**LastModifiedDate**and**CreatedDate**fields are blank or not 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.

Read ABS() Function in Salesforce | Calculate absolute value in Salesforce

With this, we now know about the **Salesforce Last Activity Date Formula**. Next, we will move ahead and 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.

**Step 1:** Click the **Setup** icon in the top right corner of the page to access Salesforce Setup.

**Step 2:** Click **Object Manager **from the menuâ€™s left side.

**Step 3:** 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.

**Step 4: **Choose **Fields & Relationships**.

**Step 5: **Next, select **New**.

**Step 6:** Choose the **Formula** as the field type.

**Step 7:** Click **Next** to proceed.

**Step 8:** 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**.

**Step 9: **Select **Date** as the Formula Return Type. After that, click **Next**.

**Step 10: **Enter the formula that calculates the last activity date in the Advance Formula editor. The formula is given below:

```
IF(
NOT(ISBLANK(LastModifiedDate)),
LastModifiedDate,
IF(
NOT(ISBLANK(CreatedDate)),
CreatedDate,
null
)
)
```

**Step 11:** To verify that the formula is valid, click **Check Syntax**.

**Step 12:** We can specify **how you want to handle the empty field** and include the **Description** and **Help Text** as alternatives.

**Step 13: **Then, select **Next**.

**Step 14:** Select the appropriate field **Level Security** and to make it visible to everyone, here we select the **Visible** checkbox.

**Step 15: **Select **Next**.

**Step 16: **Select the **Page Layout** Name for which the formula field is to be added.

**Step 17: **Click **Save** to save the formula field.

We can use the formula field once weâ€™ve created it. Letâ€™s look at an example:

- Create a contact or open the already created contact by opening the
**Contacts**item and saving it. - 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 advance formula to** calculate the last activity date. Now, weâ€™ll look at how to use the advance formula in Salesforce Classic to determine the last activity date.

## Last Activity Date Formula Field in Salesforce Classic

Here, are the steps to define the Salesforce last activity date formula field in Salesforce Classic.

**Step 1:** From the Salesforce Lightning to open your Salesforce Classic edition. Click on **Avtar** and then click **Switch to Salesforce Classic**.

**Step 2:** Click on the **Setup** option.

**Step 3:** Scroll down to the **Build **section. Then under **Customize**, select the object for whom we want to calculate the last activity date. Here, I choose the **Leads** from the object list.

**Step 4:** Click on the dropdown menu and select **Fields**.

**Step 5:** As you scroll down the page, click on the **New** button under **Custom Fields & Relationships.**

**Step 6:** Select the **Formula** as the field type.

**Step 7:** Click **Next** to proceed.

**Step 8:** Enter a **Field Label** for the formula, and the **Field Name** will be automatically populated. Here, I enter **Field Label** as **Lead Activity Date**.

**Step 9: **Select **Date **as the Formula Return Type. After that, click **Next**.

**Step 10: **Enter the formula that calculates the last activity date in the Advance Formula editor. The formula is given below:

```
IF(LastModifiedById <> null, LastModifiedDate,
IF(CreatedById <> null, CreatedDate, null)
)
```

**Step 11:** To verify that the formula is valid, click **Check Syntax**.

**Step 12:** We can specify **how you want to handle the empty field** and include the **Description** and **Help Text** optionally.

**Step 13: **Then, click **Next**.

**Step 14:** Choose the appropriate **Fieldâ€™s Level Security**, and then check the box **Visible** to make it visible to all.

**Step 15:** Click **Next**.

**Step 16:** Choose the **Page Layout Name** for which the formula field is to be added.

**Step 17:** Click **Save** to save the formula field.

Once weâ€™ve defined the formula field, we may use it. Letâ€™s explore an example:

- Create or Open a lead by opening the
**Leads**tab and saving it. - Then, In the
**detail**section, we will get the**Lead Activity Date**field which shows the result based on the last activity performed on the record.

We now understand the advanced formula to determine the** last activity date in Salesforce Classic**.

## 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 both Salesforce Classic and Salesforce Lightning.

In addition to this, the following are the topics that we have discussed:

- Salesforce Last Activity Date Formula
- Last Activity Date Formula Field in Salesforce Lightning
- Last Activity Date Formula Field in Salesforce Classic

You may also like the following Salesforce tutorials:

- Salesforce Date Range Formula
- Salesforce Formula Field to Check Null Values for Dates
- 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.