Blog

Validation rules can be a powerful tool to help maintain data integrity in systems. They’re custom logic tests you define so data has to meet certain standards or format before being saved. The test is run and returns either true (there is an error, do not save the record) or false (validation succeeded, carry on). In the case of an error, a message will display on the screen, the user can correct said error. Happy days.

Sounds great – who wouldn’t want that everywhere?!

Not so fast. When used wisely, validation rules are a great ally, but can equally become the stuff of nightmares when they’re not implemented appropriately or overused.  A common pitfall of adding validation rules to an existing system is that it can prevent existing records from being saved when reopened by an unsuspecting user who is challenged to provide a value for a field for which they are not responsible for or have no knowledge of. Imagine that pickle for a thousand records.

These “hidden figures” work in the background (users never see them) and they are also run before any other automation rules are processed. That’s good news for an administrator because they get a first say on what is not valid upon record-save, but we must consider all the automation processes which exist downstream, particularly when adding a new validation rule to an established system.  These rules are run underneath the UI, the API, any AppExchange add-on or custom code, even Visualforce pages, which means that changes in validation could prevent existing processes or integrations from working as originally designed.

More validation rules don’t necessarily make for a better Salesforce system. Validation rules primarily help to protect data integrity, requiring that a value that is critical to system operation is provided in the correct format. If you want to improve data quality, there are a few different tools you can try before turning to validation rules. So ask yourself a few questions first:

  • If you want every new Contact record created by your salesperson to have the phone number entered, you don’t need to create a validation rule for that.  Is it the case where you can simply mark a field as required on the page layout?

Use different page layouts to make different requirements for certain profiles or mark a field as universally required for all users.

  • Can you create picklist values and dependent picklists (and perhaps mark those fields as required as well) to narrow down value possibilities? If you want to avoid typos or duplicates, create picklist values for a State field, for instance.
  • Can you use lookup filters instead? They can give you similar results if you want to limit the number of available options.

Having said that, there are cases where validation rules are the best tool for the job. The good news is that in Salesforce, administrators create them declaratively (point-and-click). But you need to to write formulas that follow a Boolean logic (bad news if writing formulas is not your thing).

Writing formulas from scratch can be intimidating for some but the formula wizard in Salesforce will help you check for syntax errors (you can also read this handy tutorial here). I strongly suggest you test any formula on a Developer Org or in a Sandbox environment before deploying it.

There are plenty of resources online (you can find the links at the end of this post) that can help you craft a formula specific to your case. Most of the time, you can find a pre-made expression for a similar scenario where it can easily be tweaked to fit your needs. Be careful though, because even official documentation can contain formula errors.

So always test your formulas in a safe environment first!

A Few Handy Formula Functions for Validation Rules:

Use:  NOT (ISBLANK)

When: Blank entries are accepted as a possible value. E.g. Account Number must be numeric if not blank.

Use: REGEX

When:  A field value must have a specific format.  E.g. Email field must contain a valid email address format.

When there is a predictable pattern of numbers, letters and punctuation, REGEX is your friend.

REGEX stands for Regular Expression and is used when you want the value to follow a specific format. Social Security Number is a classic example but you can use as a rule for Driver’s License numbers that have letters and numbers together, postal codes etc.

Use: REGEX and LEN together in the same expression to specify the format and length of the value to be entered. (Alternatively, you can set the specific length of a custom field in the field options)

Tip: You can download a list of US Zip Codes in CSV format here.

Use:  ISNEW

When: The rule should only apply on record creation

or

Use: ISCHANGED

When: the rule should apply when a field changes.

Did You Know?

You can include the RecordType.Id merge field in your formula

When: You need to apply different validations for different record types.

  • If your org has multiple page layouts for the object on which you create a validation rule, check that the rule works as intended on each layout.

New in Spring ’17:

Include IsPersonAccount to a criteria

When: You want to ignore Person Accounts from the Name field in Account-related rules.

Previously, Account-related processes that used the Name field only evaluated Business Account records, but as of Spring ’17, Person Accounts are automatically factored in. Source

  • When you want one or more fields to be conditionally required depending on the value of another field. E.g., when Opportunity Stage is Closed/Lost a validation rule can enforce that the field “Loss reasons” has a meaningful value.
  • If you want a discount percentage to have different limits for different roles or users, a validation rule referring to Profile.Name, User.Id or UserRole.Name may be your solution. Sample User Role and Profile Validation Rules

Keep in Mind:

  • Validation Rules don’t apply if you create new records for an object with Quick Create.
  • If your organization has any integrations that use this object, verify that the validation rule functions as intended for each integration.
  • Validation rules run even if the field referred in the formula is not on a page layout.

Finally, before deploying a new validation rule, make a plan for how to update existing records. E.g. Run a report to find potential errors, can you use Data Loader to insert new values that observe the new criteria or will you have users enter them manually?

Do you have a favorite validation rule formula or tip? Share with us in the comments!

Other Helpful Links:

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications

Validation Rules: Salesforce’s Hidden Figures

Validation rules can be a powerful tool to help maintain data integrity in systems. They’re custom logic tests you define so data has to meet certain standards or format before being saved. The test is run and returns either true (there is an error, do not save the record) or false (validation succeeded, carry on). In the case of an error, a message will display on the screen, the user… Read More

Validation Rules: Salesforce’s Hidden Figures

Creating Validation Rule Formulas – A Quick Tutorial

This tutorial covers some basic functions and logic that are useful when creating formulas in Salesforce. The examples below specifically refer to Validation Rule formulas, which can sometimes behave slightly different from other formulas in Salesforce. When writing a new formula or validation rule, I always like to have a tab open with a  “formula cheat sheet”, like this one. Remember: Validation rules prevent records from being saved when the result… Read More

Creating Validation Rule Formulas – A Quick Tutorial

What is the Approval Process in Salesforce?

Salesforce CRM isn’t the number one customer relationship management program for nothing. Aside from the core functionality, however, there is so much opportunity and peripheral usefulness built into the Salesforce platform that it has evolved into its own ecosystem in which organizations can live and self-sustain without much need to venture into other software. The drawback to this ecosystem is simply that each niche requires exploration to discover why, how,… Read More

What is the Approval Process in Salesforce?

Focus on People: Brian Lueken From Call Center to 16X Certified

Brian Leuken is an Application Architect for a large healthcare corporation. Rumor has it, that they have the largest Service Cloud healthcare implementation in the U.S. The implementation is growing right now – they’ve got licenses for 6,000, and it’s growing to around 21,000 in the next five years. The user population varies from frontline call center representatives to back office processing of all of the mountains and mountains of forms,… Read More

Focus on People: Brian Lueken From Call Center to 16X Certified

Offline access to your Salesforce data

Did you know that it is possible to access and edit your Salesforce data when you are offline? Although we are surrounded by internet connectivity most of the time, we are constantly on-the-go and having access to important data, even without internet access, is a great advantage. So how does offline view and edit access actually work? Offline access is possible when caching and Offline Edit is enabled for users…. Read More

Offline access to your Salesforce data

Focus on People: Jordan Elkin

Jordan Elkin is a Technical Consultant. He always knew that Technology Consulting was going to be his field, but he was on the look out for how to get started. Soon enough, he learned of the existence of Salesforce, and wanting to get to know it, watched some of the online sessions from Dreamforce 2015. He developed his Salesforce skills over the next few months, received his certifications, and now works… Read More

Focus on People: Jordan Elkin

Delivering successful Salesforce projects using Agile

Aymeric Zito is the CEO of ProQuest Consulting. In this article, he discusses how ProQuest have been so successful using the Agile project methodology to deliver Salesforce projects. Before we learn more about how Proquest uses Agile, can you tell us about your background and how you got started with Salesforce? My background is in neuroscience and software engineering. I started my career programming enterprise web applications in Java J2E and moved… Read More

Delivering successful Salesforce projects using Agile

Focus on People: Alex Bassett

Alex Bassett is a Salesforce Consultant based in Vancouver, Canada. Alex was originally working as a Data Reporting & Information Analyst, but upon learning about Salesforce and its opportunities, decided to begin his climb to get certified. After receiving his Certified Salesforce Administration designation in June 2016, he quickly found a job as a Salesforce Consultant. Learn about Alex’s Salesforce journey below. How and Why did you get started with Salesforce?… Read More

Focus on People: Alex Bassett

Apex Best Practices – Avoid Exceeding Governor Limits

Apex Code is the Force.com programming language used by developers to build custom business logic on the platform by writing Apex Triggers, custom VisualForce controllers and extensions, Anonymous Apex codes, etc. It runs in a multi-tenant environment where a single resource can be shared by all different Salesforce organisations or instances. In this case, it is crucial to ensure that no organisation would monopolise the resources. Salesforce.com enforced a set… Read More

Apex Best Practices – Avoid Exceeding Governor Limits

Salesforce Lead Process

Salesforce is a CRM or Customer Relationship Management tool and as such, its primary use is to manage the relationship between a business and their customers. Prior to consumers or businesses becoming customers, however they start out as potential leads. In this post are the basics of how to utilize Salesforce to track leads, convert them to deals and best practice around when to do so.All businesses are unique so… Read More

Salesforce Lead Process

Focus on People: Nick Liechty

Nick Liechty is a next-generation innovative Salesforce leader with a unique combination of technical expertise and enterprise experience across a variety of industries. Having architected and led dozens of clients through their journey into the Salesforce ecosystem, he is definately one of the leaders of the pack. Below he shares some of his experiences and tips with you: How and Why did you get started with Salesforce? I was doing… Read More

Focus on People: Nick Liechty

Extending Social Sign-On in Communities

By: Warren Mangahas With an ever-expanding number of social media platforms, the need for companies to accommodate third-party logins is increasingly paramount. Even if you have a fantastic Salesforce Community set up, full of valuable resources and a vibrant user-base, the idea of having to sign up on another site and memorize another password may just be enough to turn someone off from signing up. This is where Salesforce Social Sign-On… Read More

Extending Social Sign-On in Communities

Customizing a Flow User Interface

Flows are a very useful way for developers to create standardize business processes and perform actions in Salesforce, without writing any code. Some examples of where Flows can be useful include helping your Customer Service team provided consistent service across your organization by standardizing questions and scripts, or Flows can be used internally to help maintain data integrity. When you embed your Flow into your user’s UI, you will usually… Read More

Customizing a Flow User Interface

Focus on People: Nancy Johnson

Nancy Johnson is a high level Project Manager hailing from Sydney, Australia. Having focused on being a Project Manager and Business Analyst during her career, getting Salesforce certified was her next logical step. Nancy shares her Salesforce journey with us below. How and Why did you get started with Salesforce? I am a very experienced Project Manager and a friend asked me to be a Project Manager at her organization… Read More

Focus on People: Nancy Johnson