Skip to content

Check whether open Opportunities have Contact Roles

Create a Check that compares the number of open Opportunities with Contact Roles against the total number of open Opportunities. Equal counts mean every open Opportunity is covered.

One aggregate query counts distinct covered Opportunities and another counts all open Opportunities. Compare two queries can compare those values without Apex.

  • Confirm your process requires at least one Contact Role on every open Opportunity.
  • Confirm intended users can read Opportunity and Opportunity Contact Role records and fields.
  • Decide whether Accounts with no open Opportunities should pass. Both counts are zero here, so they pass.
  • Save new configuration inactive and validate it before activation.

Use or create an Account Check Set named Account Record Alignment. Run it on click, show Found/Expected on demand, and leave it inactive until validation succeeds.

Open Setup → Custom Metadata Types → Record Health Check → Manage Records, select New, and enter:

Salesforce fieldValue
LabelOpen Opportunities Have Contact Roles
Record Health Check NameOpen_Opportunities_Have_Contact_Roles
Check SetAccount Record Alignment
Check TitleOpen Opportunities have Contact Roles
Evaluation TypeCompare two queries
Source QuerySELECT COUNT_DISTINCT(OpportunityId) coveredCount FROM OpportunityContactRole WHERE Opportunity.AccountId = {!record.Id} AND Opportunity.IsClosed = false
Source Query FieldcoveredCount
Comparison QuerySELECT COUNT() FROM Opportunity WHERE AccountId = {!record.Id} AND IsClosed = false
How To Read Query ResultsOne row or aggregate
Comparison OperatorEquals
Failure SeverityInfo
Message When Failed{!record.Name fallback="This Account"} has one or more open Opportunities with no Contact Roles.
Fix MessageAdd the appropriate stakeholder Contact Roles before forecast review.
Action LabelReview opportunities
Action URL/lightning/r/Account/{!record.Id}/related/Opportunities/view
Evaluation Order10
ActiveUnchecked until validation succeeds

The Source result is Found and the Comparison result is Expected. The distinct count avoids counting an Opportunity twice when it has several Contact Roles.

  1. Run the configuration-validation Flow.
  2. Correct every error and review the zero-opportunity behavior.
  3. Activate the Check and Check Set only after validation succeeds.
  4. Test from the Account page with Record Health Check Card User.
Open OpportunitiesOpportunities with a Contact RoleExpected result
00Pass
10Info
11Pass
32Info
33Pass

Repeat with intended sharing because both counts reflect records visible to the running user.

The card compares the two visible query results using the configured list or numeric operator.

Result detailMeaning
PASSThe source and comparison results satisfy the configured operator.
FAILThe results do not satisfy the operator, and the card shows the configured guidance.
SKIPPEDThe Check does not apply or a configured prerequisite did not pass.
FoundThe normalized result returned by the source query.
ExpectedThe normalized result returned by the comparison query.
What you seeCheck this first
Found is larger than expectedConfirm COUNT_DISTINCT(OpportunityId) and alias coveredCount
Accounts with no pipeline should skipAdd an approved applicability or prerequisite rule; this example intentionally passes 0 = 0
Counts differ from a reportRun the report with the same user and matching filters
Unable to CheckConfirm access to both objects, relationship fields, and queried fields