Validation rules enforce conditions a record must meet before it can be saved, going beyond simply marking fields required.
On this page:
How they work
Marking a field required on a Page Layout covers the simple case. Validation rules handle everything else: administrators write a formula, and the record cannot be saved until the formula is satisfied. They work on all standard and custom objects.
Formulas are written in C# and must return a Boolean. Like calculated fields, they are code, so get help from someone who writes C-family languages if you do not. If-else statements are the working structure, and the formula cannot contain:
- for loops
- do while loops
- method declarations
Every rule is object-specific. A rule that should apply across several objects has to be created separately on each one.
Validation rules can also restrict who edits what, going beyond what Field Level Permissions and Advanced Permissions can express on their own.
⚠️ Validation rules apply to the web application only. They do not run in the sidebars or add-ons, so a record created through the Gmail or Outlook sidebar is not checked against them.
When rules trigger, and when they do not
They trigger on manual or API creation and editing of a record, and on edits to Lead Status, Opportunity or Quote Status, Opportunity or Project Pipeline Stage, and on converting a Lead.
They do not trigger when Insightly Workflow Automation creates or edits records, or when a record is created through conversion.
⚠️ Automation bypasses validation. A rule that blocks bad data on manual entry will not block the same data arriving through a workflow. Anything that has to hold under all conditions needs enforcing somewhere else as well.
Creating a rule
- Click the profile icon and select System Settings.
- Click Objects and Fields.
- Select the object the rule applies to.
- Click Validation Rules, then New Rule.
- Complete the required fields:
Rule Name. Name it for what it enforces, such as “The first name can’t equal test”.
- Error Message. The text shown when the rule rejects a save.
- Error Location. Where the message appears on the record page. Selecting Top of Page puts it at the top.
- Enter the formula in Rule Formula. The Helpers button opens the Object Fields and Functions lists. Add values by double-clicking or dragging an item across, by typing directly, or by pasting a formula such as the examples below. Object Fields are sorted by type, so String Fields lists the text fields. Functions are sorted by return type, including Boolean, DateTime, and Decimal. Clicking a function shows its description.
- Click Validate Formula. If the formula cannot compute, an error appears above the formula field explaining why.
- Click Create Validation Rule.
Return statements have to use one of two values:
-
Validation.IsErrorreturns your error message and blocks the save. -
Validation.IsValidclears the error and allows it.
A rule cannot be saved unless it returns a value and the formula validates.
Worked examples
Copy these into the Rule Formula field. Each is object-specific, so create it on the object it applies to.
Reject a placeholder first name. Prevents users saving “Test” as a first name. Swap the string for any other value you want to block.
if (Record.FIRST_NAME == "Test"){ return Validation.IsError;} else {
return Validation.IsValid; }
Require an organization on a contact. For teams who create contacts and forget to link them.
if(Record.ORGANISATION_ID != null){ return Validation.IsValid;}else{
return Validation.IsError;}
Reject personal email domains. Blocks addresses containing “gmail”, to keep records on business domains.
var test = Record.EMAIL_ADDRESS?.Contains("gmail") ?? false;
if (test == true){
return Validation.IsError;
}
else {
return Validation.IsValid;
}
Cap a discount at 15%. For accounts using Products, Price Books, and Quotes.
if(Record.Discount_Offered__c > 15){ return
Validation.IsError;}else{ return Validation.IsValid;}
Stop a due date preceding a start date.
if(Record.DUE_DATE != null && Record.START_DATE != null && Record.DUE_DATE <
Record.START_DATE){ return Validation.IsError;}else{ return
Validation.IsValid;}
Check digit length on a numeric field. Intended for validating phone numbers.
String a = Record.Your_Field__c.ToString();
if(a.Length >= 10)
{
return Validation.IsValid;
}
else
{
return Validation.IsError;
}
Block a dropdown value. Prevents users selecting the value “Error”.
if (Record.Dropdown_Field__c == "Error"){
//show validation error when the field value is "Error"
return Validation.IsError;
}
return Validation.IsValid;