The client wanted all mobile numbers entered in Salesforce to be exactly 10 digits. They need this validation to ensure accurate communication with their customers.
Any number shorter or longer than 10 digits should trigger an error message and prevent the record from being saved.
As a Salesforce Admin, I used the LEN() function in validation to automatically check the length of the mobile number field and enforce this requirement.
In this article, we will learn how to calculate the length of a text using the LEN() function in Salesforce. We will also cover the syntax and real-world scenarios where we can use the Salesforce LEN function.
What is the LEN() Function in Salesforce?
The Salesforce LEN function is used to return the number of characters in a specified text. In addition to this, you can use this LEN() function in various functions, formulas, workflows, conditional formatting, and process automation.
The syntax of the LEN function is as given below:
LEN(text)
Here, the text parameter is the text string or the field whose length you want to calculate.
Let’s see some use cases of how to use the LEN function in Salesforce:
Suppose you are working in an e-commerce company as a Salesforce developer, and you are handling the Orders object of Salesforce to keep track of orders.
To store the orders, you create a field named order number, but you also want to ensure that all order numbers meet a specific length requirement.
So, to enforce that all order numbers must be exactly 6 characters long, you decided to use the LEN function of Salesforce. The following is the formula for this example:
LEN(Order_Number__c) <> 6
With this, we have learned what the LEN function is, its syntax, and its use case. Now, we will learn how to use the LEN Formula in Salesforce.
How to Use the LEN() Function in Salesforce
The following steps show how to use the LEN() function to determine the length of text in Salesforce. Let’s use a scenario to understand the concept.
- Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click “Setup“ from the dropdo