Opportunity Validation Rules
Opportunity Close Date In The Past
Design
As a Salesforce User
I want the system to prevent the Close Date from being in the past when an opportunity is changed to Closed Won or Closed Lost
So that I can ensure the data is accurate and up-to-date
Given I am on an Opportunity record page
When I change the opportunity stage to Closed Won or Closed Lost
Then an error message is displayed if the Close Date is in the past
Build
Rule Name: Close_Date_In_The_Past
Description: Prevent the Close Date from being in the past when the opportunity stage is Closed Won or Closed Lost
Error Condition Formula:
Rule Name: Close_Date_In_The_Past
Description: Prevent the Close Date from being in the past when the opportunity stage is Closed Won or Closed Lost
Error Condition Formula:
AND(
ISCHANGED(StageName),
CloseDate < TODAY(),
OR(
ISPICKVAL(StageName, "Closed Won"),
ISPICKVAL(StageName, "Closed Lost")
)
)
Error Message: Close Date cannot be in the past when closing an opportunity
Error Location: Close Date
Test
Steps
- Open an Opportunity record page
- Set the Close Date to a past date
- Change the stage to Closed Won or Closed Lost
- Click Save
Expected Results
- An error message is displayed
- The error message should read 'Close Date cannot be in the past when closing an opportunity'
Opportunity Stage Mandatory Fields
Design
As a Salesforce User
I want the system to enforce mandaotry fields at pre-defined opportunity stages
So that I can ensure the data is accurate and complete
Given I am on an Opportunity record page
When the stage is changed to pre-defined opportunity stages
Then the relevant fields are mandatory and an error message is displayed if the fields are empty
Build
Rule Name: {stage-name}_Stage_Mandatory_Fields
Description: Enforce mandatory fields when the stage is'{stage-name}'
Error Condition Formula:
AND(
ISCHANGED(StageName),
ISPICKVAL(StageName, "Example_Stage_Name"),
OR(
ISPICKVAL( Example_Picklist_Field, ""),
ISBLANK( Example_Text_Field )
)
)
Error Message: {Example_Picklist_Label} and {Example_Text_Label} are mandatory when the stage is '{stage-name}'
Error Location: Top of the page | Field
Test
Steps
- Open an Opportunity record page
- Change the stage to '{stage-name}'
- Leave the {Example_Picklist_Label} and {Example_Text_Label} fields empty
- Click Save
Expected Results
- An error message is displayed
- The error message should read '{Example_Picklist_Label} and {Example_Text_Label} are mandatory when the stage is '{stage-name}'
Specific Record Type Opportunity Stage Mandatory Fields
Design
As a Salesforce User
I want the system to enforce mandaotry fields at pre-defined {record-type} opportunity stages
So that I can ensure the data is accurate and complete
Given I am on an {record-type} Opportunity record page
When the stage is changed to pre-defined Opportunity stages
Then the relevant fields are mandatory and an error message is displayed if the fields are empty
Build
Rule Name: {record-type}_{stage-name}_Stage_Mandatory_Fields
Description: Enforce mandatory fields when the record type is {record-type} and the stage is' {stage-name}'
Error Condition Formula:
AND(
RecordType.DeveloperName == "Example_Record_Type_Name",
ISCHANGED(StageName),
ISPICKVAL(StageName, "Example_Stage_Name"),
OR(
ISPICKVAL(Example_Picklist_Field, ""),
ISBLANK(Example_Text_Field)
)
)
Error Message: {Example_Picklist_Label} and {Example_Text_Label} are mandatory when the stage is '{stage-name}' on '{record-type}' opportunities
Error Location: Top of the page | Field
Test
Steps
- Open an Opportunity record page with the record type '{record-type}'
- Change the stage to '{stage-name}'
- Leave the {Example_Picklist_Label} and {Example_Text_Label} fields empty
- Click Save
Expected Results
- An error message is displayed
- The error message should read '{Example_Picklist_Label} and {Example_Text_Label} are mandatory when the stage is '{stage-name}' on '{record-type}' opportunities