Skip to content

Apex Check examples

Example3 min read

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.

ExampleQuestion it answersApex classInstalls with the package?
Check that an Account has recent activityDoes the Account have enough Tasks and Events in a date window?AccountHasRecentActivityCheckYes
Check open Opportunities for combined risksDoes any open Opportunity have all three risk signs at once?AccountOpenOpportunityHealthCheckNo; a developer deploys it
Score a customer Account’s readinessDoes the Account score high enough on four weighted signals?AccountStrategicReadinessCheckNo; a developer deploys it

If no reviewed class exists in your org, use a Formula, Query, or Compare two queries example instead.

FieldWhat to enter
Evaluation TypeVerify with Apex
Apex ClassThe class name, such as AccountHasRecentActivityCheck. For a class in another package’s namespace, enter namespace.ClassName.
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.

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.

ValueContents
scope.recordIdsThe IDs of the records to check, without duplicates
scope.parametersThe Apex Parameters (JSON) values as a map
Returned Map<Id, rhc.RecordHealthCheckOutcome>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.

Result on the cardCommon cause
Unable to CheckThe class is not found, is not a Record Health Check plugin, or its parameters are not valid.
System ErrorThe 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.