Stage Progression Validation (Salesforce)

Prevent Opportunity Stage progression based on certain requirements being met in Accord.

Overview

  1. What is a validation rule?
  2. Setting up a validation rule
  3. Writing a validation rule

What is a Validation Rule?

Validation Rules prevent a Salesforce record from being created and/or saved. The goal is to write an Error Condition Formula that represents the scenario you’re trying to block

 

Setting Up a Validation Rule

The most common validation rule we recommend limiting the progression of an Opportunity without a Customer invited to an Accord. This acts as a gate to ensure your AEs and CSMs are properly using the Customer Collaboration Platform.


Step 1: Navigate to the Object Manager page for Opportunity, then choose “Validation Rules”

 

Step 2: Click the New button on the Validation Rules page


Step 3: Populate Validation Rule settings/values (modify the example below as relevant for your use case)

Screenshot 2023-01-17 at 5.21.01 PM

  • Create a Rule Name and Description
    • Example Rule Name: Accord_Customer_Invite_Block_Progression
    • Description: Prevents Stage progression beyond Qualification without Customer invitation
      • Note: The Description is visible only to Salesforce Admins and should describe the intention of this Validation Rule.
  • Check “Active” when the Validation Rule is ready to be activated
  • Error Message
    • Example Error Message: “Opportunities must have at least 1 Accord Customer invitee to progress beyond Prospecting or Qualification.”
    • Note: The error message should be descriptive enough for the user to understand why their record save was blocked, as well as provide guidance on how to resolve the block

Step 4: Click Save to save the new Validation Rule

Step 5: (Optional, strongly recommended) Test the Validation Rule

  • When you’re ready to test, be sure to enable the “Active” box on the Validation Rule.
  • Create multiple Opportunities with both the error and non-error cases. 

Writing a Validation Rule

"Writing" a validation rule is really drafting an error condition formula. There are multiple ways of writing a formula that delivers the same result. Below we are going to cover an easy way to write your validation rule for Accord. 

(a) Identify who the rule should apply to

First, identify who the Validation Rule should be applied to. 

The example above illustrates two different ways of doing this – based on a User's Manager ID or a specific User's ID.

(

$User.Id = "005Dn000005EGEi"

||

$User.ManagerId = "005Dn000005EGEn"

)
&&

Salesforce Validation Rules allow evaluation of data on the record itself, and/or data on the User record, Profile record, or UserRole record of the person committing the record save.

Caution: When writing and testing Validation Rules in Sandbox, be sure to confirm that any referenced IDs are the same in both Sandbox and Production. If the referenced IDs are different in Production, be sure to add a migration step to address the ID difference when promoting the Validation Rule to Production. (Salesforce IDs will generally match for any metadata/records automatically generated during new Sandbox creation. Salesforce IDs will not match for records/metadata written after Salesforce’s automated new Sandbox creation process.)

Note: Be mindful of the character limits on Validation Rule formulas (~3900 characters). As a best-practice, we recommend limiting the count of included/excluded Users/Roles/Profiles to no more than ~15-20. 

(b) Exclude who the rule should not apply to

This section tells the Validation Rule to exclude certain groups of users. 

In this example, the "System Administrator" and "Custom: Sales Manager Profile" will be excluded from evaluation.

If you'd like to exclude any users or groups of users from Validation Rule evaluation, add them here. (eg. your "Integration User" or "Automated Processes User")

 

NOT( 

$Profile.Name = "System Administrator"

||

$Profile.Name = "Custom: Sales Manager Profile"



)

 

(c) Evaluate the Opportunity fields 

This section evaluates the Accord-related Opportunity fields on the Opportunity record.

In this example, we're ignoring Opportunities where at least 1 Customer has been invited to or has accepted an invitation to the related Accord.

Note: You might be wondering why this formula uses the "NOT()" convention instead of "Invites<1". This is to cover the "NULL" value case when an Accord has not yet been linked to the Opportunity. 

&&

NOT(

Number_of_Customers_Invited__c >= 1

||

Number_of_Customers_Accepted__c >= 1

)

(d) Pick which Stages the rule applies to

This section evaluates the "current" (PRIORVALUE) Opportunity Stage to see if the Validation Rule should be considered.

In this example, we want the Validation Rule to be evaluated only when the Opportunity is in one of the earlier Stages. i.e. If the Opportunity is already in a later Stage, this Validation Rule will not fire. (We're presuming that if the Opportunity is already in a later stage, a Customer has probably already been engaged, so no need to do a data check here.)

&&

(

ISPICKVAL( PRIORVALUE( StageName ), "Prospecting")

||

ISPICKVAL( PRIORVALUE( StageName ), "Qualification")

)

(e) Exclude irrelevant stages

This section evaluates the "to-be" Opportunity Stage to see if the Validation Rule should be considered. i.e. "What will be the Stage after the rep clicks the Save button?"

In this example, we're ignoring any Opportunities that are in an early Stage. The idea is that Opportunity save should be allowed during early Stages, even if a Customer has not yet been invited to the related Accord.


Additionally, we’re allowing Opportunities to progress to the “Closed Lost” Stage, regardless of whether any Customers had been invited to the Accord.

&&

NOT(

ISPICKVAL( StageName , "Prospecting")

||

ISPICKVAL( StageName , "Qualification")

||

ISPICKVAL( StageName , "Closed Lost")

)

  • The end result of the formula above would evaluate as: 
    • IF the user clicking the Save button on the Opportunity is 005Dn000005EGEi, and/or the user’s manager is 005Dn000005EGEn.
      AND the user clicking the Save button on the Opportunity is NOT a System Admin or Sales Manager,  
    • AND if the Number of Customers Invited or Accepted is 0 or NULL,
    • AND if the Opportunity is in an early Stage,
    • AND if the Opportunity is being moved to a later Stage,
    • THEN block the Opportunity Save
  • Some notes on the symbols in the formula above:
    • && means “AND”. Salesforce formulas may use either or both the && convention, and/or the AND(criteria1,criteria2,criteria3) convention, depending on your preference.  
    • || means “OR”. Salesforce formulas may use either or both the || convention, and/or the OR(criteria1,criteria2,criteria3) convention, depending on your preference. 

Helpful links for Salesforce Validation Rules: