Skip to content

Check whether an Account has a Contact

Setup reference: Query Check configuration

Create a Query Check that counts Contacts related to the Account. The Check passes when the count is greater than zero and guides the user to the Contacts related list when none are found.

Contacts are separate records, so an Account formula cannot count them. Verify with a query can count the related records without custom Apex. This should guide a handoff rather than block every Account save with a Validation Rule.

  • Confirm that at least one Contact is required for your handoff process.
  • Confirm that intended users can read Contact and Contact.AccountId.
  • Remember that the count reflects records visible to the running user.
  • Save new configuration inactive and validate it before activation.

To create a Check Set, open Setup → Custom Metadata Types → Record Health Check Set → Manage Records, select New, and enter:

Salesforce fieldValue
LabelAccount Related Record Review
Record Health Check Set NameAccount_Related_Record_Review
ObjectAccount
Card TitleAccount Related Record Review
Card SubtitleConfirm related records are ready for handoff.
When Checks RunWhen the user clicks Run
Summary DisplayShow below checks
Found/Expected DisplayShow on demand
ActiveUnchecked until validation succeeds

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

Salesforce fieldValue
LabelHas At Least One Contact
Record Health Check NameHas_At_Least_One_Contact
Check SetAccount Related Record Review
Check TitleHas at least one Contact
Evaluation TypeVerify with a query
Source QuerySELECT COUNT() FROM Contact WHERE AccountId = {!record.Id}
How To Read Query ResultsOne row or aggregate
Comparison OperatorGreater than
Expected Value Comes FromFixed value
Expected Value (Fixed)0
Failure SeverityWarning
Message When Failed{!record.Name fallback="This Account"} has no Contacts. Add at least one Contact before continuing.
Message When Unable To EvaluateUnable to count Contacts. Confirm access to Contact and AccountId.
Fix MessageAdd a Contact related to this Account.
Action LabelReview contacts
Action URL/lightning/r/Account/{!record.Id}/related/Contacts/view
Evaluation Order10
ActiveUnchecked until validation succeeds

COUNT() returns one aggregate result. A result greater than zero passes.

  1. Run the configuration-validation Flow.
  2. Correct every error and review every warning.
  3. Set the Check and Check Set to Active only after validation succeeds.
  4. Add Record Health Check to the Account Lightning record page and select the Check Set.
  5. Assign Record Health Check Card User to the people testing the card.
Contacts visible to the userExpected result
0Warning; Found is 0 and Expected is 0 with a Greater than comparison
1Pass
More than 1Pass

Repeat the tests with the sharing and field access intended users receive. This Check confirms a visible Contact, not necessarily every Contact related to the Account.

The card reads the visible query result and compares it with the configured expected value.

Result detailMeaning
PASSThe query result satisfies the configured comparison.
FAILThe query result does not satisfy the comparison, and the card shows the configured guidance.
SKIPPEDThe Check does not apply or a configured prerequisite did not pass.
FoundThe normalized row, list, or aggregate value returned by the query.
ExpectedThe configured fixed value or evaluated expected formula.
What you seeCheck this first
The count is lower than expectedConfirm Contact sharing and Read access for the running user
Every Account failsConfirm the comparison is Greater than, not Greater than or equal
Unable to CheckConfirm access to Contact and AccountId and validate the SOQL
Review contacts does not openConfirm the Account Contacts related-list API name in your org