Salesforce Last Activity Date Formula

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.

Salesforce Last Activity Date Formula
Salesforce Last Activity Date Formula

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.

Salesforce Last Activity Date Formula Example
Salesforce Last Activity Date Formula Example

Step 4: Choose Fields & Relationships.

Step 5: Next, select New.

Salesforce Lightning Last Activity Date Formula
Salesforce Lightning Last Activity Date Formula

Step 6: Choose the Formula as the field type.

Step 7: Click Next to proceed.

Salesforce Lightning Last Activity Date Formula Example
Salesforce Lightning Last Activity Date Formula Example

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.

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

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.

Last Activity Date Formula Field in Salesforce Lightning Example
Last Activity Date Formula Field in Salesforce Lightning Example

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.

Last Activity Date Formula Field using Salesforce Lightning
Last Activity Date Formula Field using Salesforce Lightning

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.

Last Activity Date Formula Field using Salesforce Lightning Example
Last Activity Date Formula Field using Salesforce Lightning Example

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.
Last Activity Date Formula Field in Salesforce Example
Last Activity Date Formula Field when the record is created.
Last Activity Date Formula Field in Salesforce
Last Activity Date Formula Field when the record is modified.

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.

Last Activity Date Formula Field in Salesforce Classic
Switch to Salesforce Classic

Step 2: Click on the Setup option.

Last Activity Date Formula Field in Salesforce Classic Example
Last Activity Date Formula Field in Salesforce Classic Setup

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.

Last Activity Date Formula Field using Salesforce Classic
Lead Last Activity Date Formula Field

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

Last Activity Date Formula Field using Salesforce Classic Example
Last Activity Date Formula Field using Salesforce Classic Example

Step 6: Select the Formula as the field type.

Step 7: Click Next to proceed.

Salesforce Classic Last Activity Date Formula
Salesforce Classic Last Activity Date Formula

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.

Salesforce Classic Last Activity Date Formula Example
Salesforce Classic Last Activity Date Advance Formula Example

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.

Salesforce Classic Last Activity Date Formula Field
Salesforce Classic Last Activity Date Formula Field

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.

Salesforce Classic Last Activity Date Formula Field Example
Salesforce Classic Last Activity Date Formula Field Example

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.

Salesforce Classic Example Last Activity Date Formula Field
Salesforce Classic Example Last Activity Date 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.
Last Activity Date Formula using Salesforce Classic Example
Last Activity Date Formula when the lead is modified.
Last Activity Date Formula using Salesforce Classic
Last Activity Date Formula when the lead is created.

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: