Skip to content
Suggest a correction

Check that an Account has at least one Contact

Example4 min read

Create a Record Health Check that counts the Contacts related to an Account and passes when there is at least one. When there are none, the card links to the Account’s Contacts related list. The example uses the Verify with a query Evaluation Type with a COUNT() query.

Contacts are separate records related to the Account, so a formula on the Account cannot count them. One SOQL query can. Use a Check rather than a Validation Rule because an Account without Contacts is a gap to fix before a handoff, not a reason to block every Account update.

  • Install Record Health Check, and assign yourself Record Health Check Admin and the Salesforce Customize Application permission.
  • Confirm that the people who will use the card can read Contacts. The count includes only Contacts the running user can see.

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 Related Record Review
ObjectAccount
Record Health Check Set NameAccount_Related_Record_Review
ActiveCleared until validation succeeds
Card TitleAccount Related Record Review
Card SubtitleConfirm related records are ready for handoff.
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
LabelHas At Least One Contact
Check SetAccount Related Record Review
Evaluation TypeVerify with a query
Record Health Check NameHas_At_Least_One_Contact
Evaluation Order10
ActiveCleared until validation succeeds
Source QuerySELECT COUNT() FROM Contact WHERE AccountId = {!record.Id}
Source Query FieldLeave blank
How To Read Query ResultsOne row or aggregate
Comparison OperatorGreater than
Expected Value Comes FromFixed value
Expected Value (Fixed)0
Check TitleAccount has at least one Contact
Check DescriptionPasses when the Account has one or more Contacts that you can see.
Message When Failed{!record.Name fallback="This Account"} has no Contacts. Add at least one before handoff.
Fix MessageAdd a Contact for this Account, then run the Check again.
Message When Unable To EvaluateUnable to count Contacts. Confirm that you can read Contacts.
Failure SeverityWarning
Action LabelReview Contacts
Action URL/lightning/r/Account/{!record.Id}/related/Contacts/view

How the values work:

  • SELECT COUNT() returns one number, the count of matching Contacts. Leave Source Query Field blank, because a bare COUNT() returns the number directly.
  • {!record.Id} inserts the open Account’s ID. Do not put quotation marks around it.
  • Greater than with an expected value of 0 passes when the count is 1 or more.
  • A COUNT() query always returns a number, even 0, so If Query Finds No Records does not apply.
  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 Related Record Review (Account_Related_Record_Review), and activate the page.
  4. Assign Record Health Check Card User to the users who test the card.

Select Run on the card for each case.

Contacts the user can seeResult on the cardFoundExpected
0Warning0more than 0
1Pass1more than 0
5Pass5more than 0

Also run the card as a user who cannot see any of the Account’s Contacts. The Check shows Warning for that user, because it counts only visible Contacts.

A failed row shows Warning, the message, the fix message, a Review Contacts link, and Found and Expected values. Expected combines the operator and the value, so it reads “more than 0”.

What you seeWhat to check
Every Account failsComparison Operator is Greater than and the expected value is 0.
The count is lower than expectedThe running user’s access to the Account’s Contacts.
Unable to CheckThe user can read Contacts, and Source Query matches the table exactly.
A validation error on Source Query FieldLeave it blank for a bare COUNT() query.