0% found this document useful (0 votes)
44 views5 pages

What Is Salesforce Validation Rule?: Assignment-6 Implementing Business Logics Using Validations

Uploaded by

Rupan Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views5 pages

What Is Salesforce Validation Rule?: Assignment-6 Implementing Business Logics Using Validations

Uploaded by

Rupan Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment-6

Implementing Business Logics using Validations

Validation Rules

What is Salesforce Validation Rule?

• Validation rules in Salesforce verify the data a user enters in a record.

• The data should meet the standards specified by the organization.

• It can contain a formula or expression that evaluates the data in one or more fields &
returns a value of true or false.

Validation Rules also include an error message to display to the user when the rule returns a value
true due to an invalid value/data.

After you have defined validation rules:


1.The user chooses to create a record or edit an existing record.
2.The user clicks Save.
3.All validation rules are verified.
•If all data is valid, the record is saved.
•If any data is invalid, the associated error message displays without saving the record.
4.The user makes the necessary changes and clicks Save again.

Types of Validation

1. System Validation

• System Validation are enforced by salesforce like numbers should be in a valid format.

• It also includes required.

• Unique fields as well.

2. User-Defined Validation(Custom Validation)

User-Defined Validation(Custom Validation) are build using validation rules.


Most Commonly Used Functions
• ISBLANK(field)-returns true if the field is blank.
• ISPICKVAL- (picklist field, specific picklist value) returns true if a picklist value in a field
matches the picklist value in the formula.
• TEXT()- converts a picklist value to text, a quirk for writing formulas that ask if a picklist
field is blank/not blank.
• AND()- returns true if all the items or functions are true.
• OR()- returns true if any of the items or functions are true.

Defining Validation Rules


You can create validation rules for objects, fields, campaign members, or case milestones.
In these steps, we create a validation rule that fires when a user tries to save an account
with an account number of incorrect length.

Creating a Validation Rule


1. From Setup, go to Object Manager and click Account.
2. In the left sidebar, click Validation Rules.
3. Click New.
4. Enter the following properties for your validation rule:
a. Rule Name: Account_Number_8_Characters
b. Error Condition Formula:
LEN( AccountNumber) != 8

5. Error Message: Account number must be 8 characters long.


6. To check your formula for errors, click Check Syntax.
7. Click Save to finish.
Here’s how a validation rule’s error message can appear when a user types an incorrect
account number format into a field.
Examples of Validation Rules
Here are some validation rule examples that you can try out yourself.

1 Quantity should not be negative


2. Visit Date should not be greater than today.
3. Invoice Amount should not be greater than 10000

Date Must Be in the Current Year


The YEAR function returns the four-digit year of a given date.

The TODAY function returns the current date. The <> (Not Equal) operator determines if a value is
not equal to another value (if it is either less than or greater than the other value.)

In the example, the validation rule determines if the year of a given date is not equal to the year
of today’s date. A value of "True" indicates that the data entered by the user contains an invalid
value. That is, if the user enters a date that is not in the current year, the validation rule returns a
response of "True" and sends an error message.
Field Value
Validates that a custom date field contains a date within the current
Description:
year.
Formula: YEAR( My_Date__c ) <> YEAR ( TODAY() )
Error Message: Date must be in the current year.
Error
My Date
Location:

Number Range Validation


In the example, the validation rule determines if the difference between two values (Salary Max
and Salary Min) is greater than $20,000.

A value of "True" indicates that the data entered by the user contains an invalid value.

That is, if the user enters two values whose difference exceeds the $20,000 salary range, the
validation rule returns a response of "True" and sends an error message.

Field Value
Validates that the range between two custom fields, Salary Min and Salary Max, is
Description:
no greater than $20,000.
(Salary_Max__c - Salary_Min__c) > 20000
Formula:

Error
Salary range must be within $20,000. Adjust the Salary Max or Salary Min values.
Message:
Error
Salary Max
Location:

Account Number Is Numeric


The AND function returns a value of "True" if all values in the formula are true, and a value of
"False" if one or more values are false.

The ISBLANK function determines if an expression has a value.

The ISNUMBER function determines if an expression's value is a number.

The NOT function determines if the inverse of an expression is true. In the example, the validation
rule determines if an account number is both not blank and not a number.

A value of "True" indicates that the data entered by the user contains an invalid value. That is, if
the user enters a non-numeric value for an account number, the validation rule returns a response
of "True" and sends an error message .
Field Value
Validates that the Account Number is numeric if not
Description:
blank.
AND(
NOT(ISBLANK(AccountNumber)),
NOT(ISNUMBER(AccountNumber))
Formula:
)

Copy
Error Message: Account Number is not numeric.
Error
Account Number
Location:

You might also like