Check that an Account has recent activity
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.
Why Apex fits
Section titled “Why Apex fits”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.
What the class counts
Section titled “What the class counts”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.
| Parameter | Meaning | Default | Allowed values |
|---|---|---|---|
daysBack | How many days back the window starts | 30 | 1 to 3,650 |
minimumActivities | How many activities are needed to pass | 1 | 1 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.
Before you start
Section titled “Before you start”- 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.
Step 1: Create or choose the Check Set
Section titled “Step 1: Create or choose the Check Set”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.
| Field | Value |
|---|---|
| Label | Account Apex Readiness |
| Object | Account |
| Record Health Check Set Name | Account_ |
| Active | Cleared until validation succeeds |
| Card Title | Account Readiness |
| Card Subtitle | Confirm recent engagement and pipeline readiness. |
| When Checks Run | When the user clicks Run |
| Found/Expected Display | Show on demand |
Step 2: Create the Check
Section titled “Step 2: Create the Check”Open Setup → Custom Metadata Types, select Manage Records next to Record Health Check, select New, enter these values, and save.
| Field | Value |
|---|---|
| Label | Has Recent Activity |
| Check Set | Account Apex Readiness |
| Evaluation Type | Verify with Apex |
| Record Health Check Name | Account_ |
| Evaluation Order | 10 |
| Active | Cleared until validation succeeds |
| Apex Class | AccountHasRecentActivityCheck |
| Apex Parameters (JSON) | {"daysBack": 90, "minimumActivities": 2} |
| Check Title | Account has recent activity |
| Check Description | Passes when the Account has at least two Tasks or Events in the last 90 days. |
| Message When Failed | {!record. |
| Fix Message | Log any customer activity that has not been recorded, or plan the next follow-up. |
| Message When Unable To Evaluate | Unable to check recent activity. |
| Failure Severity | Warning |
| Action Label | Log activity |
| Action URL | /lightning/o/Task/new?defaultFieldValues=WhatId={!record. |
| Applies To | All 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.
Step 3: Validate and activate
Section titled “Step 3: Validate and activate”- Run the Validate Record Health Check Configuration Flow action, as described in Validate configuration before activation, and correct every error.
- Activate the Check, then the Check Set.
- Add the Record Health Check component to the Account record page, select Account Apex Readiness (Account_Apex_Readiness), and activate the page.
- Assign Record Health Check Card User to the users who test the card.
Step 4: Test the Check
Section titled “Step 4: Test the Check”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 days | Result on the card | Found | Expected |
|---|---|---|---|
| 0 | Warning | 0 | 2 |
| 1 | Warning | 1 | 2 |
| 2 | Pass | 2 | 2 |
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.
What users see
Section titled “What users see”The class adds its own text to the card, which replaces the Check’s text when the Check fails:
| Part of the row | What the user sees |
|---|---|
| Label | Warning, 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 link | Open account, which opens the Account |
| Found and Expected | The 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.
Resolve problems
Section titled “Resolve problems”| What you see | What to check |
|---|---|
| Unable to Check | Apex Parameters (JSON) uses only daysBack and minimumActivities, as whole numbers within range. |
| A known Task is not counted | The Task is closed, Related To is the Account, its due date is inside the window, and the user can see it. |
| System Error | The user can read Tasks and Events. See Troubleshoot with the browser console. |
| The class is not found | Apex Class is exactly AccountHasRecentActivityCheck. |