Skip to content
Suggest a correction

Check that an Account has recent activity

Example5 min read

Create a Record Health Check that passes when an Account has at least two activities in the last 90 days. The Check uses AccountHasRecentActivityCheck, an Apex class that installs with Record Health Check, so you configure it in Setup without writing code. The example uses the Verify with Apex Evaluation Type.

The rule counts two kinds of related records, Tasks and Events, applies a date window, and compares the total with a minimum. A formula cannot count related records, and one query cannot combine Tasks and Events. The packaged class does all of this and lets you set the window and the minimum with JSON parameters.

AccountHasRecentActivityCheck adds up, for each Account:

  • Tasks whose Related To field is the Account, that are closed, and whose Due Date is on or after the start of the window; and
  • Events whose Related To field is the Account and whose date is on or after the start of the window. Events scheduled in the future are counted too.

A Task or Event related only to a Contact or Lead through its Name field is not counted. Only activities the running user can see are counted.

ParameterMeaningDefaultAllowed values
daysBackHow many days back the window starts301 to 3,650
minimumActivitiesHow many activities are needed to pass11 to 1,000

A value outside its range, a value that is not a whole number, or an unknown parameter name makes the Check show Unable to Check, with reason code INVALID_APEX_PARAMETERS.

  • Install Record Health Check, and assign yourself Record Health Check Admin and the Salesforce Customize Application permission.
  • Agree on the window and the minimum. This example uses 90 days and two activities.
  • Confirm that the people who will use the card can read Tasks and Events.

You can add the Check to an Account Check Set you already have. To create one, open Setup → Custom Metadata Types, select Manage Records next to Record Health Check Set, select New, enter these values, and save. Leave other fields at their defaults.

FieldValue
LabelAccount Apex Readiness
ObjectAccount
Record Health Check Set NameAccount_Apex_Readiness
ActiveCleared until validation succeeds
Card TitleAccount Readiness
Card SubtitleConfirm recent engagement and pipeline readiness.
When Checks RunWhen the user clicks Run
Found/Expected DisplayShow on demand

Open Setup → Custom Metadata Types, select Manage Records next to Record Health Check, select New, enter these values, and save.

FieldValue
LabelHas Recent Activity
Check SetAccount Apex Readiness
Evaluation TypeVerify with Apex
Record Health Check NameAccount_Has_Recent_Activity
Evaluation Order10
ActiveCleared until validation succeeds
Apex ClassAccountHasRecentActivityCheck
Apex Parameters (JSON){"daysBack": 90, "minimumActivities": 2}
Check TitleAccount has recent activity
Check DescriptionPasses when the Account has at least two Tasks or Events in the last 90 days.
Message When Failed{!record.Name fallback="This Account"} has fewer than two activities in the last 90 days.
Fix MessageLog any customer activity that has not been recorded, or plan the next follow-up.
Message When Unable To EvaluateUnable to check recent activity. Confirm that you can read Tasks and Events.
Failure SeverityWarning
Action LabelLog activity
Action URL/lightning/o/Task/new?defaultFieldValues=WhatId={!record.Id}
Applies ToAll records

Enter the class name exactly as shown, without a namespace prefix; Record Health Check finds the packaged class. The Action URL opens a new Task with Related To set to the Account; the user still reviews and saves it.

  1. Run the Validate Record Health Check Configuration Flow action, as described in Validate configuration before activation, and correct every error.
  2. Activate the Check, then the Check Set.
  3. Add the Record Health Check component to the Account record page, select Account Apex Readiness (Account_Apex_Readiness), and activate the page.
  4. Assign Record Health Check Card User to the users who test the card.

Use sandbox Accounts and activities related to them through Related To. Select Run on the card for each case.

Qualifying activities in the last 90 daysResult on the cardFoundExpected
0Warning02
1Warning12
2Pass22

Also confirm that these do not change the count: a Task related only to a Contact, an open Task, and a Task with a due date more than 90 days ago. Then enter {"daysBack": 0} in a sandbox, confirm Unable to Check, and restore the original JSON.

The class adds its own text to the card, which replaces the Check’s text when the Check fails:

Part of the rowWhat the user sees
LabelWarning, from Failure Severity
Message“Recent follow-up is below the configured activity requirement.” followed by an Open account link
Fix instructions“Log a completed Task or Event for this Account, then run the Check again.”
Action linkOpen account, which opens the Account
Found and ExpectedThe activity count and the minimum, such as Found 1 and Expected 2. Unlike a Query Check, the Expected value has no “at least” wording

The Check’s Message When Failed, Fix Message, Action Label, and Action URL are fallbacks: the card shows them if the class’s text is missing or not valid. Write them anyway, so the row always has useful guidance.

What you seeWhat to check
Unable to CheckApex Parameters (JSON) uses only daysBack and minimumActivities, as whole numbers within range.
A known Task is not countedThe Task is closed, Related To is the Account, its due date is inside the window, and the user can see it.
System ErrorThe user can read Tasks and Events. See Troubleshoot with the browser console.
The class is not foundApex Class is exactly AccountHasRecentActivityCheck.