Skip to content
Suggest a correction

Check open Opportunities for combined risks

Example5 min read

Create a Record Health Check on an Account that fails when any open Opportunity has all three of these warning signs at once: no activity in the last 30 days, no Next Step, and a Close Date outside the current calendar quarter. The example uses the Verify with Apex Evaluation Type with a custom Apex class, AccountOpenOpportunityHealthCheck, that a developer creates and deploys.

This Apex class does not install with Record Health Check. A developer must create, test, and deploy it from Open Opportunity health: Apex implementation before you configure the Check. Without the class, the Check shows Unable to Check.

The rule needs all three warning signs on the same Opportunity. Three separate query Checks would each fail on different Opportunities, and a single query cannot easily express “outside the current quarter” together with the other conditions. A short Apex class can test each Opportunity and return one result for the Account.

  • Install Record Health Check, and assign yourself Record Health Check Admin and the Salesforce Customize Application permission.
  • Confirm that the AccountOpenOpportunityHealthCheck class is deployed in the org: in Setup, open Apex Classes and find it.
  • Agree on the stale-activity window. This example uses 30 days. The class uses calendar quarters, not custom fiscal periods.
  • Confirm that the people who will use the card can read Opportunities and their Last Activity, Next Step, and Close Date fields.

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
LabelOpen Opportunities Are Healthy
Check SetAccount Apex Readiness
Evaluation TypeVerify with Apex
Record Health Check NameOpen_Opportunities_Are_Healthy
Evaluation Order20
ActiveCleared until validation succeeds
Apex ClassAccountOpenOpportunityHealthCheck
Apex Parameters (JSON){"staleDays": 30}
Check TitleNo open Opportunity has all three risk signs
Check DescriptionFails when an open Opportunity has no activity in 30 days, no Next Step, and a Close Date outside this quarter, all at once.
Message When FailedOpen Opportunities on {!record.Name fallback="this Account"} with no recent activity, no Next Step, and a Close Date outside this quarter: {!rhcResult.foundValue}.
Fix MessageFor each affected Opportunity, log current activity, enter a Next Step, or correct the Close Date.
Message When Unable To EvaluateUnable to check open Opportunities. Confirm that you can read Opportunities and their Next Step and Close Date fields.
Failure SeverityCritical
Action LabelReview open Opportunities
Action URL/lightning/r/Account/{!record.Id}/related/Opportunities/view
Applies ToWhen a count query matches
Applies When (Count Query)SELECT COUNT() FROM Opportunity WHERE AccountId = {!record.Id} AND IsClosed = false
Count Must BeGreater than
Count Value0
Message When Not Applicable{!record.Name fallback="This Account"} has no open Opportunities.

How the values work:

  • staleDays sets how many days without activity make an Opportunity stale. The class accepts 1 to 3,650. A missing or out-of-range value silently uses 30, so always enter the value you intend.
  • The class returns the number of Opportunities with all three signs as Found, and 0 as Expected.
  • Applies To skips Accounts with no open Opportunities before the class runs.
  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.

Last Activity on an Opportunity comes from its completed activities, so create dated Tasks or Events to set it. Select Run on the card for each case.

Open Opportunities on the AccountResult on the card
NoneSkipped
One with all three signsFailed
One with recent activity, a Next Step, or a Close Date in this quarterPass
Two, each with only one or two of the signsPass

Also run the failing case as a user who cannot see that Opportunity; the result follows that user’s access.

A failed row shows Failed, because Failure Severity is Critical, with the message, the fix message, and a Review open Opportunities link. Found shows the count of risky Opportunities, and Expected shows 0. An Apex Check’s Expected value has no comparison wording such as “to equal”.

What you seeWhat to check
Unable to Check with the class not foundThe class is deployed, and Apex Class is exactly AccountOpenOpportunityHealthCheck.
An Opportunity with all three signs passesAll three conditions are true on that one Opportunity, and Apex Parameters (JSON) is valid.
Skipped on an Account with open OpportunitiesThe user can see them, and Applies When (Count Query) matches the table.
System ErrorThe user can read Opportunities and the queried fields.