You are on page 1of 8

Salesforce Validation Rules Scenarios

Scenario 1: Complex Validation Rule for Opportunity Probability


Scenario: Ensuring Probability Alignment
Description: Validate that the Opportunity Probability matches the corresponding Opportunity Stage.
Validation Rule Name: Probability_Alignment_Validation
Validation Rule Description: Ensure the Opportunity Probability aligns with the corresponding Opportunity
Stage.
Validation Rule Formula:
AND(
OR(
ISPICKVAL(StageName, "Prospecting"),
ISPICKVAL(StageName, "Qualification")
),
Probability <> 10
OR(
ISPICKVAL(StageName, "Needs Analysis"),
ISPICKVAL(StageName, "Proposal/Price Quote")
),
Probability <> 25
OR(
ISPICKVAL(StageName, "Negotiation/Review"),
ISPICKVAL(StageName, "Closed Won"),
ISPICKVAL(StageName, "Closed Lost")
),
Probability <> 50
OR(
ISPICKVAL(StageName, "Contract Sent"),
ISPICKVAL(StageName, "Contract Negotiation")
),
Probability <> 75
OR ISPICKVAL(StageName, "Closed Won"), Probability <> 100
)
Error Message: The Opportunity Probability does not match the corresponding Opportunity Stage.
Explanation: This complex validation rule ensures that the Opportunity Probability field is aligned with the
corresponding Opportunity Stage. It checks multiple conditions using the ISPICKVAL function and logical
operators (AND, OR) to verify the correct probability values based on each stage.

For example, if the stage is "Prospecting" or "Qualification," the probability must be different from 10%.
Similarly, for stages like "Needs Analysis" or "Proposal/Price Quote," the probability should not be 25%.

By implementing this validation rule, data integrity is maintained, preventing data inconsistencies and
providing accurate insights into sales pipeline management.

Scenario 2: Compound Validation Rule for Contact Duplication


Scenario: Preventing Duplicate Contacts
Description: Ensure that duplicate contacts with the same email address are not created.
Validation Rule Name: Contact_Duplication_Validation
Validation Rule Description: Prevent the creation of duplicate contacts based on the email address.
Validation Rule Formula:
AND(
NOT(ISBLANK(Email)),
ISNEW(),
By: Sweta Prajapati (Salesforce Developer)
Salesforce Validation Rules Scenarios
ISDUPLICATEVALUE(Email)
)

Error Message: A contact with the same email address already exists.
Explanation: This compound validation rule tackles the challenge of preventing duplicate contacts based on
the email address field. It checks if the Email field is not blank, if it's a new record, and if the Email field value
already exists in another contact record.
By leveraging the ISDUPLICATEVALUE function, Salesforce compares the Email field value with
existing contacts and triggers the validation rule when a duplicate email is detected.
Implementing this validation rule helps maintain a clean and accurate contact database, preventing duplicate
entries and streamlining communication and relationship management
Note: The ISDUPLICATEVALUE function requires enabling Duplicate Management in Salesforce to
work properly.

Scenario 3: Limiting the Discount Percentage on Opportunities

Formula:
AND(
ISPICKVAL(StageName, "Closed Won"),
ISCHANGED(Discount_Percentage__c),
Discount_Percentage__c > 0.2
)
Explanation: In this scenario, we want to enforce a validation rule that restricts the discount percentage on
opportunities. The rule applies when the opportunity reaches the "Closed Won" stage and the discount
percentage is modified. The formula checks if the Discount_Percentage__c field is greater than 0.2 (or 20%).
If the condition evaluates to true, the validation rule triggers an error, preventing the opportunity from being
saved. This helps maintain pricing integrity and prevents excessive discounting. 💰🔒

Scenario 4: Complex Validation Rule for Contact Duplicate Prevention (Contact Details Prevention
Rule)
Scenario: Preventing Duplicate Contacts based on Email and Phone
Formula:
AND(
OR(
ISCHANGED(Email),
ISCHANGED(Phone)
),
ISNEW(),
OR(
ISBLANK(Email),
ISBLANK(Phone),
NOT(ISNULLVALUE(Email)),
NOT(ISNULLVALUE(Phone))
),
OR(
ISNEW(),
NOT(CONTAINS(Email, LEFT(Phone, 3)))
),
OR(

By: Sweta Prajapati (Salesforce Developer)


Salesforce Validation Rules Scenarios
ISNEW(),
NOT(CONTAINS(Phone, LEFT(Email, 3)))
)
)
Explanation: In this complex scenario, we aim to prevent the creation of duplicate contacts based on email
and phone number. The formula checks if either the email or phone field has changed, indicating a potential
duplicate. It also ensures that either the email or phone is provided and not null. Additionally, the formula
checks if the email and phone do not share the same first three characters, avoiding false positives due to
common phone prefixes. If the conditions are met, the validation rule triggers an error, preventing the creation
of duplicate contacts.

Scenario 5: Complex Validation Rule for Opportunity Probability


Scenario: Create a validation rule to prevent an opportunity with a probability greater than 50% from being
closed as "Lost".
Formula:
AND(
ISPICKVAL(StageName, "Lost"),
Probability > 50
)
Explanation: This validation rule ensures that opportunities with a probability greater than 50% cannot be
closed as "Lost". It helps enforce realistic forecasting by preventing high probability opportunities from being
marked as lost without further investigation.

Scenario 6: Dependent Validation Rule for Account Industry and Type


Scenario: Develop a dependent validation rule that requires specific Account Types based on the selected
Industry.
Formula:
AND(
ISPICKVAL(Industry, "Healthcare"),
NOT(ISPICKVAL(Type, "Hospital"))
) ||
AND(
ISPICKVAL(Industry, "Technology"),
NOT(ISPICKVAL(Type, "Software"))
)
Explanation: This validation rule ensures that for Accounts in the Healthcare industry, the Account Type
must be set to "Hospital". Similarly, for Accounts in the Technology industry, the Account Type must be set
to "Software". It enforces data consistency and accurate categorization based on industry-specific
requirements.

Scenario 7: Cross-Object Validation Rule for Contact and Opportunity Relationship


Scenario: Implement a validation rule that prevents the creation of an Opportunity without a related Contact.
Formula:
AND(
ISNEW(),
ISBLANK(ContactId),
NOT(ISBLANK(AccountId))
)
By: Sweta Prajapati (Salesforce Developer)
Salesforce Validation Rules Scenarios
Explanation: This validation rule ensures that when creating a new Opportunity, a related Contact is
specified. It allows the Opportunity to be associated with a specific individual, enhancing data integrity and
providing better visibility into the sales process.

Scenario 8: Hierarchical Validation Rule for Account Hierarchy


Scenario: Create a validation rule to enforce a specific naming convention for Account names within a
hierarchical structure.
Formula:
AND(
NOT(ISBLANK(ParentId)),
NOT(REGEX(Name, "[A-Z]{2,}-[0-9]{3,}-[A-Z]{2,}"))
)
Explanation: This validation rule ensures that child Accounts within a hierarchical structure follow a specific
naming convention, such as XX-000-YY. It promotes consistency and helps maintain a standardized naming
structure for Accounts in the Salesforce org.

Scenario 9: Restricting Opportunity Closure Without Required Products


Formula:
AND(
ISPICKVAL(StageName, "Closed Won"),
NOT(ISBLANK(TEXT(Product__c)))
)
Explanation: In this scenario, the goal is to prevent users from closing an opportunity as "Closed Won" if no
products have been associated with it. This validation rule checks if the opportunity stage is "Closed Won"
and if the product field (Product__c) is not blank. If the product field is blank, indicating no associated
products, the validation rule triggers an error message, ensuring that only opportunities with associated
products can be closed as "Closed Won."

Scenario 10: Enforcing Unique Combination of Field Values


Formula:
ISNEW() && ISDUPLICATE(
AccountId,
ContactId,
Product__c
)
Explanation: In this challenging scenario, we want to enforce a unique combination of field values when
creating a new record. This validation rule checks if the current record is new (ISNEW()) and uses the
ISDUPLICATE() function to check for duplicates based on a combination of fields: AccountId, ContactId,
and Product__c. If a duplicate record with the same combination of values is found, the validation rule triggers,
preventing the creation of duplicate records. This ensures data integrity and eliminates redundancy.

Scenario 11: Date Validation Based on Related Record


Formula:
CloseDate < Opportunity__r.CreatedDate
Explanation: Here, the aim is to validate the Close Date of an opportunity based on the created date of its
related record. The validation rule compares the Close Date (CloseDate) of the opportunity with the Created
Date (CreatedDate) of the related record (Opportunity__r). If the Close Date is earlier than the Created Date,
By: Sweta Prajapati (Salesforce Developer)
Salesforce Validation Rules Scenarios
indicating an invalid sequence, the validation rule triggers an error message. This ensures that the Close Date
always falls after the Created Date, maintaining data consistency and accurate reporting.

Scenario 12: Unique Combination of Fields


Formula:
ISNEW() && NOT(ISBLANK(Field1)) && NOT(ISBLANK(Field2)) &&
ISDUPLICATERECORD([SELECT Id FROM Object__c WHERE Field1 = :Field1 AND Field2 = :Field2])
Explanation: This validation rule ensures that when creating a new record in the "Object__c" object, the
combination of "Field1" and "Field2" is unique. It uses the "ISDUPLICATERECORD" function to query
existing records and checks if any matching records already exist. If a duplicate is found, the rule triggers,
preventing the creation of the duplicate record. This maintains data integrity and avoids redundancy.

Scenario 13: Date Range Validation


Formula:
AND(
NOT(ISBLANK(StartDate__c)),
NOT(ISBLANK(EndDate__c)),
EndDate__c < StartDate__c
)
Explanation: This validation rule ensures that the "EndDate__c" field is always greater than or equal to the
"StartDate__c" field. If the end date is earlier than the start date, the rule triggers, preventing the record from
being saved. This validation helps enforce the correct sequencing of dates and avoids illogical date ranges.

Scenario 14: Complex Credit Limit Validation


Formula:
AND(
NOT(ISBLANK(CreditLimit__c)),
ISNEW() && CreditLimit__c < 0,
OR(
RecordType.DeveloperName = 'HighRiskAccount',
RecordType.DeveloperName = 'VIPAccount',
RecordType.DeveloperName = 'SpecialAccount'
)
)
Explanation: This validation rule enforces complex credit limit validation for specific record types. It allows
a negative credit limit value only for specific record types: 'HighRiskAccount', 'VIPAccount', and
'SpecialAccount'. For all other record types, a negative credit limit is not permitted. If a new record is created
with an unsupported record type and a negative credit limit, the rule triggers, preventing the record from being
saved. This ensures consistent credit limit validation based on record type.

Scenario 15: Restricting Opportunity Stage Progression


Formula:
AND(
ISPICKVAL(PRIORVALUE(StageName), "Prospecting"),
ISPICKVAL(StageName, "Closed Won")
)
Explanation: This validation rule prevents the stage of an opportunity from progressing directly from
"Prospecting" to "Closed Won." It ensures that intermediate stages, such as "Qualification" or "Needs
By: Sweta Prajapati (Salesforce Developer)
Salesforce Validation Rules Scenarios
Analysis," are completed before reaching the "Closed Won" stage. This rule helps maintain a structured sales
process and accurate forecasting.

Scenario 16: Preventing Duplicate Contact Email within an Account


Formula:
AND(
NOT(ISBLANK(Email)),
ISNEW(),
ISDUPLICATEVALUE(Email, AccountId)
)
Explanation: This validation rule prevents the creation of duplicate contact records within the same account
based on email addresses. It uses the ISDUPLICATEVALUE function to check if the email value already
exists for contacts related to the same account. By enforcing this rule, data duplication is minimized, ensuring
a clean and organized contact database.

Scenario 17: Validating Product Quantity against Inventory


Formula:
AND(
ISCHANGED(Quantity),
Quantity > Product__r.Inventory__c
)
Explanation: This validation rule checks if the quantity entered for a product exceeds the available inventory
quantity. If the quantity changes and is greater than the inventory quantity associated with the product, the
rule triggers an error. This ensures that sales representatives cannot sell more products than what is available
in inventory, avoiding stockouts and backorders.

Scenario 18: Enforcing Unique Opportunity Names within an Account


Formula:
AND(
NOT(ISBLANK(Name)),
ISNEW(),
ISDUPLICATEVALUE(Name, AccountId)
)
Explanation: This validation rule ensures that opportunity names are unique within each account. When
creating a new opportunity, the rule checks if the name already exists within the same account. If a duplicate
name is detected, an error is displayed, prompting the user to choose a different name. This prevents confusion
and data overlap when managing opportunities.

Scenario 19: Restricting Account Deletion with Associated Opportunities


Formula:
AND(
ISDELETED(),
NOT(ISBLANK(Opportunities))
)

By: Sweta Prajapati (Salesforce Developer)


Salesforce Validation Rules Scenarios
Explanation: This validation rule prevents users from deleting an account that has associated opportunities.
When someone attempts to delete an account, the rule checks if any related opportunities exist. If opportunities
are present, the deletion is blocked, ensuring that important sales data is not accidentally lost.

Scenario 20: Enforce Unique Combination of Fields


Formula:
AND(
ISNEW(),
ISPICKVAL(Stage, "Closed Won"),
ISBLANK(CloseDate)
)
Explanation: This validation rule ensures that when an opportunity's stage is set to "Closed Won," the Close
Date field must be populated. This rule prevents users from closing an opportunity without specifying the
date, maintaining data integrity and accurate reporting. 💰📅 #Salesforce #DataValidation

Scenario 21: Limit Maximum Number of Characters


Formula:
LEN(Description) > 500
Explanation: In this scenario, the validation rule checks if the length of the Description field exceeds 500
characters. If it does, the rule triggers an error message, preventing users from entering lengthy or excessive
text. This helps maintain data consistency and prevents oversized descriptions. 📝✅ #Salesforce #DataQuality

Scenario 22: Complex Date Validation


Formula:
AND(
ISNEW(),
CONTAINS(TEXT(Custom_Field__c), "XYZ"),
NOT(ISBLANK(Custom_Date_Field__c)),
Custom_Date_Field__c < TODAY() + 30
)
Explanation: This validation rule ensures that when a record is created, the Custom_Field__c contains
"XYZ," the Custom_Date_Field__c is not blank, and the date is within the next 30 days. If any of these
conditions are not met, an error message is displayed, prompting users to review and correct the data. 📆🌟
#Salesforce #DataValidation

Scenario 23: Hierarchical Relationship Validation


Formula:
ISCHANGED(ManagerId) && NOT(ISBLANK(ManagerId)) && ISBLANK(Custom_Field__c)
Explanation:
This validation rule checks if the ManagerId field is changed and not blank while the Custom_Field__c is
blank. When a user updates the ManagerId field, the rule triggers an error message, ensuring that the
Custom_Field__c is also populated. This validation helps maintain consistent data in hierarchical
relationships. 👥✨ #Salesforce #DataQuality

By: Sweta Prajapati (Salesforce Developer)


Salesforce Validation Rules Scenarios
Scenario 24: Complex Email Validation
Formula:
AND(
ISNEW(),
NOT(REGEX(Email, "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b")),
ISPICKVAL(LeadSource, "Web")
)
Explanation: In this scenario, the validation rule ensures that when creating a new lead with a LeadSource of
"Web," the Email field must contain a valid email address format. If the email is incorrectly formatted, the
rule triggers an error message, prompting users to enter a valid email address

Scenario 25: Enforcing a Custom Sequential Numbering Format


Formula:
NOT(
REGEX(Order_Number__c, "^ORD-[0-9]{3}$")
)
Explanation: In this scenario, let's assume you have a custom field called "Order Number"
(Order_Number__c) on the Opportunity object, and you want to enforce a specific sequential numbering
format like "ORD-001". The validation rule checks if the Order Number matches the desired format using a
regular expression. If the Order Number doesn't match the pattern, the validation rule triggers an error
message, prompting users to correct the format and maintain data consistency.

Scenario 26: Validating Complex Date Relationships


Formula:
AND(
ISCHANGED(Start_Date__c),
End_Date__c < Start_Date__c
)
Explanation: Imagine you have two custom date fields, "Start Date" (Start_Date__c) and "End Date"
(End_Date__c), on an object. The validation rule ensures that when the Start Date is changed, the End Date
must be set to a date that is later than the Start Date. If the End Date is before the Start Date, the rule fires,
preventing users from saving the record until the date relationship is corrected.

Scenario 27: Checking Related Object Data Completeness


Formula:
AND(
ISPICKVAL(Status, 'Closed'),
ISBLANK(TEXT(Contact__r.FirstName)),
ISBLANK(TEXT(Contact__r.LastName))
)
Explanation:
Let's consider a scenario where you have a custom field called "Status" (Status) on the Case object and a
lookup relationship to the Contact object (Contact__c). This validation rule verifies that when the Case status
is set to "Closed," the associated Contact's first name and last name fields must not be blank. If either of these
fields is empty, the validation rule triggers an error message, ensuring that all required information is captured
before closing a case.

By: Sweta Prajapati (Salesforce Developer)

You might also like