Skip to main content

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:

  1. Create a checkbox field on Opportunity to indicate if Contact Roles exist.
  2. Use a record-triggered Flow to keep this checkbox updated as Contact Roles are added or removed.
  3. 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

  1. Navigate to Setup:
    • Click the Gear icon (top-right) > Setup
  1. Object Manager:
    • In the Quick Find box, type Object Manager, then click Object Manager.
  1. Select Opportunity:

    • Scroll down or search and click Opportunity.
  2. Create a New Field:

    • Click Fields & Relationships and then New.
  3. Choose Field Type:

    • Select Checkbox > Next.
  4. 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.

  1. Navigate to Flows:

    • From Setup, enter Flows in Quick Find > Flows
  2. New Flow:

    • Click New Flow
    • Select Record-Triggered Flow > Create.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.

  1. Navigate to Opportunity Validation Rules:

    • Setup > Object Manager > Opportunity > Validation Rules
  2. New Validation Rule:

    • Rule Name: Require_Contact_Role_for_Pipeline
    • Description: Ensures pipeline-stage Opportunities have at least one Contact Role.
  3. 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.