Salesforce Last Activity Date Formula Explained

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.

  1. 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.
Salesforce Last Activity Date Formula
  1. 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
  1. Choose Fields & Relationships. Next, select New.
Salesforce Lightning Last Activity Date Formula
  1. Select “Formula” as the field type. Click Next to proceed.
Salesforce Lightning Last Activity Date Formula Example
  1. 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.
Last Activity Date Formula Field in Salesforce Lightning
  1. 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
    )
)
  1. 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.
Salesforce Last Activity Date Formula
  1. Select the appropriate Field Level Security, and to make it visible to everyone, we select the Visible checkbox. Select Next.
Last Activity Date Formula Field using Salesforce Lightning
  1. Select the Page Layout Name for which the formula field is to be added. Click Save to save the formula field.
Last Activity Date Formula Field using Salesforce Lightning Example
  1. 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.
Last Activity Date Formula Field in Salesforce Example
Last Activity Date Formula Field in Salesforce

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:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.