Apex Check examples
Use these examples to build Record Health Checks with the Verify with Apex Evaluation Type. An Apex Check runs an Apex class that decides the result for each record. Choose it only when a formula, a query, or two compared queries cannot express the requirement, because a developer must write, test, and deploy any class that does not install with the package.
Choose an example
Section titled “Choose an example”| Example | Question it answers | Apex class | Installs with the package? |
|---|---|---|---|
| Check that an Account has recent activity | Does the Account have enough Tasks and Events in a date window? | AccountHasRecentActivityCheck | Yes |
| Check open Opportunities for combined risks | Does any open Opportunity have all three risk signs at once? | AccountOpenOpportunityHealthCheck | No; a developer deploys it |
| Score a customer Account’s readiness | Does the Account score high enough on four weighted signals? | AccountStrategicReadinessCheck | No; a developer deploys it |
If no reviewed class exists in your org, use a Formula, Query, or Compare two queries example instead.
Fields every Apex Check uses
Section titled “Fields every Apex Check uses”| Field | What to enter |
|---|---|
| Evaluation Type | Verify with Apex |
| Apex Class | The class name, such as AccountHasRecentActivityCheck. For a class in another package’s namespace, enter namespace.. |
| Apex Parameters (JSON) | Optional settings that the class reads, such as {"daysBack": 90}. Leave blank if the class takes none. |
An Apex Check returns its own Found and Expected values, so Display: Found Text, Display: Expected Text, and the display formulas do not apply. Show Found and Expected and Display: Value Format still apply.
What the class receives and returns
Section titled “What the class receives and returns”The class implements the rhc.RecordHealthCheckPlugin interface. Record Health Check calls its
evaluate method once with every record in the request: one record from the card, or up to 200 from
Flow or Apex.
| Value | Contents |
|---|---|
scope. | The IDs of the records to check, without duplicates |
scope. | The Apex Parameters (JSON) values as a map |
Returned Map<Id, rhc. | Exactly one outcome for each record ID: pass, fail, skipped, or unable to evaluate. A pass or fail outcome must also carry Found and Expected values |
The class must read data for all records with one query per object, not one query per record. It must not change data, call external services, send email, start background jobs, or publish events. Record Health Check detects data changes, callouts, email, and Queueable or future jobs and stops the Check; it cannot detect event publishing or Batch and Scheduled jobs, so code review must catch those. Write an Apex Check describes the complete interface and its tests.
What can go wrong
Section titled “What can go wrong”| Result on the card | Common cause |
|---|---|
| Unable to Check | The class is not found, is not a Record Health Check plugin, or its parameters are not valid. |
| System Error | The class threw an error while running, often because the user cannot read an object or field it queries. A missing or extra outcome, or a pass or fail without Found and Expected, also shows System Error. |