Validation rules

Validation rule for phone number in Salesforce

Validation rules in Salesforce are a useful way to guarantee that the data entered into the system meets specific standards. These rules can be applied to various fields, such as text, date, and formula fields.

By implementing validation rules, organizations can assure data accuracy and integrity, leading to better decision-making and enhanced user experience.

The phone number format varies worldwide, so it is essential to establish validation rules that account for these differences. Below we discuss how to create a simple validation rule in Salesforce to accommodate phone numbers.

How do we create a validation rule?

Start by logging into your Salesforce instance and selecting Setup. Select “Object Manager” from the “Platform Tools” section. If you want to create a validation rule for an object (for example, a contact), select that object.

Choose “Validation Rules” from the left sidebar. Click on ‘New’ and enter the details.

Specify the formula for the error condition and the message to display. The error message can be displayed either at the top of the page or below a specific field. Activate the validation rule.

The Phone number must be 10 digits:

Show an error message ‘Please enter a valid 10-digit phone number’ if the phone field on the account object doesn’t have 10 digits.

 

validation rules

validation rules

 

Phone numbers must be 10-13 digits long and only numerical values are accepted. The plus symbol at the beginning is also valid.

validation rules

 

US Phone Number

Validates that the Phone number is in (999) 999-9999 format. This works by using the REGEX function to check that the number has ten digits in the (999) 999-9999 format.

validation rules

How to Bypass the validation rule using Custom permissions?

You can keep your validation rules active and bypass them under certain circumstances by using Custom Permissions. You can define access checks using Custom Permissions via permission sets and profiles, similar to how you assign user permissions and other access settings.

Want to Learn Salesforce Flows? Checkout our Salesforce Flow Course

By using permission sets, both profiles and individual users or special groups of users can easily assign or remove Custom Permissions from their profiles.

Steps to bypass a validation rule using Custom Permissions:

Create a permission set which when assigned to a User allows him to bypass a validation rule.

validation rules

 

Go to Manage Assignments and assign it to the System Administrator.

validation rules

Click on Setup and search for Custom Permissions. Create a new custom permission.

 

From the created permission set click on ‘Custom Permissions’  and assign the required custom permission to the permission set.

validation rules

 

To bypass the Validation Rule, please navigate to the object that you want to access. Go to the validation rule and choose the Permission set from the Insert field. 

validation rules

 

Hence, the validation rule is bypassed for the system administrator.

 

validation rules

Additionally, there are alternative methods to bypass validation rules. One such method involves sending user profile details as custom metadata to the validation rule. This allows the exclusion of users with a specific profile, preventing them from being affected by the validation rule.

FAQ

1. Is it possible to temporarily disable validation rules during the process of migrating or importing data?
Yes, we can deactivate or bypass validation rules temporarily to facilitate data migration or import operations.

2. How is a validation rule different from a workflow rule in Salesforce?

Validation and workflow rules ensure proper enforcement of business processes. A validation rule ensures data integrity during record saving, preventing invalid data entry. In contrast, a workflow rule automates standard internal procedures to trigger specific actions based on specified criteria.

3. Is it possible to use validation rules to limit data entry according to user profiles?
Validation rules can restrict data entry based on user profiles. Criteria related to user profiles can ensure specific fields are only required or restricted for certain user groups.

4. Are validation rules applicable to both standard and custom objects in Salesforce?

Validation rules can be created for both standard and custom objects in Salesforce. These rules ensure data quality and consistency for any type of object.

5. Do validation rules exclusively apply to numeric and text fields?

Transitioning from this, validation rules can be extended to various data types, such as date fields, Boolean values, and other specialized formats, ensuring consistency.

Get a complete Roadmap To Learn Salesforce Admin And Development

Share Now

Similar Posts

One thought on “Validation rule for phone number in Salesforce

Leave a Reply

Your email address will not be published. Required fields are marked *