Enforcing Opportunity Contact Role Validation in Salesforce
Once an Opportunity has reached a stage that qualifies it as pipeline, sales should know who they’re selling to, right?
Right. But ensuring that opportunity contacts are selected is a step that requires validation rules. This is mission critical to understanding attribution and resource allocation.
Here is a step-by-step guide that will help reduce hemming and hawing, finger-pointing, and credit-taking.
Enforcing Opportunity Contact Role Validation in Salesforce
Goal: Once an Opportunity has reached a stage that qualifies it as pipeline, it must have at least one Contact Role associated.
Summary of Approach:
- Create a checkbox field on Opportunity to indicate if Contact Roles exist.
- Use a record-triggered Flow to keep this checkbox updated as Contact Roles are added or removed.
- Set a validation rule on the Opportunity to enforce the requirement at certain pipeline stages.
Step 1: Create a Custom Checkbox Field on the Opportunity
- Navigate to Setup:
- Click the Gear icon (top-right) > Setup
- Object Manager:
- In the Quick Find box, type Object Manager, then click Object Manager.
-
Select Opportunity:
- Scroll down or search and click Opportunity.
-
Create a New Field:
- Click Fields & Relationships and then New.
-
Choose Field Type:
- Select Checkbox > Next.
-
Enter Field Details:
- Field Label: Has_Contact_Roles
- Default Value: Unchecked (False)
- Click Next, set field-level security, then Save.
Result: You have a checkbox on the Opportunity that will track whether Contact Roles exist.
Step 2: Create a Record-Triggered Flow to Update the Checkbox
Since validation rules can’t directly check for related records, we’ll use a Flow to update our checkbox whenever a Contact Role is created, updated, or deleted.
-
Navigate to Flows:
- From Setup, enter Flows in Quick Find > Flows
-
New Flow:
- Click New Flow
- Select Record-Triggered Flow > Create.
-
Configure the Trigger:
- Object: Opportunity Contact Role
- Trigger on Create or Update.
- Also set it to run on Delete by choosing the appropriate trigger condition.
- Click Done.
-
Get Related Contact Roles:
- Click + > Get Records.
- Object: Opportunity Contact Role
- Filter:
OpportunityId = $Record.OpportunityId
- Store All Records.
- This retrieves all Contact Roles for the Opportunity that triggered the Flow.
-
Decision Element to Check Count:
- Click + > Decision.
- Outcome 1: Contact Roles Found if the Get Records result is not null.
- Default Outcome: No Contact Roles Found.
-
Update the Opportunity:
- From the Contact Roles Found outcome, + > Update Records: Set
Has_Contact_Roles__c = True
. - From the No Contact Roles Found outcome, + > Update Records: Set
Has_Contact_Roles__c = False
.
- From the Contact Roles Found outcome, + > Update Records: Set
-
Save and Activate:
- Name the Flow (e.g., “Update Opportunity Contact Role Checkbox”).
- Click Activate.
Result: Whenever a Contact Role is created, deleted, or updated, the checkbox on the related Opportunity is updated automatically.
Step 3: Create the Validation Rule on the Opportunity
Now that our checkbox (Has_Contact_Roles__c
) reflects the existence of Contact Roles, we’ll enforce the rule.
-
Navigate to Opportunity Validation Rules:
- Setup > Object Manager > Opportunity > Validation Rules
-
New Validation Rule:
- Rule Name: Require_Contact_Role_for_Pipeline
- Description: Ensures pipeline-stage Opportunities have at least one Contact Role.
-
Error Condition Formula:
Adjust stage names as needed. For example:
AND( OR( ISPICKVAL(StageName, “Qualification”), ISPICKVAL(StageName, “Proposal/Price Quote”), ISPICKVAL(StageName, “Negotiation/Review”), ISPICKVAL(StageName, “Closed Won”), ISPICKVAL(StageName, “Closed Lost”) ), NOT(Has_Contact_Roles__c)
Need help?
Our team is always here to help. Just find a time on our calendar.