While working as a Salesforce Administrator, I created a custom field to store the Account Number in the format ACC-IND-000123.
Now, the sales team has requested a new field that displays only the last 6 digits (000123) of the account number for reporting and reference purposes.
To meet this requirement, I created a formula field and used the RIGHT function in Salesforce. The RIGHT function extracts a specified number of characters from the right side of a text value.
In this article, we will learn about the RIGHT() Function in Salesforce. We will also learn the syntax and real-world scenarios where we can use the Salesforce right function.
What is the RIGHT() Function in Salesforce?
This Salesforce RIGHT() function returns the specified number of characters from the end of a text string. In simple terms, you can say that the RIGHT() function extracts the number of characters specified from the right side of the string.
You can use this function when some important information that you require is on the right side of the string. Some popular uses of the RIGHT() function include extracting product codes, last names, email domains, campaign codes, etc.
In addition, you can say that the RIGHT() function is used while extracting a substring, splitting the string, and retrieving the specific suffix codes from the string.
Furthermore, there are some considerations you should keep in mind when using the RIGHT() function in Salesforce.
- If the number of specified characters in the Salesforce right function is less than zero, the value gets replaced with zero.
- You can use the auto-number fields as text fields in Salesforce RIGHT function formulas.
The syntax of the Salesforce RIGHT function is as follows:
RIGHT(text, num_chars)
Here is a detailed description of the parameters:
- text: The text parameter specifies the text string from which you want to extract the substring.
- num_chars: The num_chars parameter specifies the total number of characters that you want to extract from the end of the text string.
Use the RIGHT() Function in Salesforce
The following steps show how to use the RIGHT function in Salesforce to return the specified number of characters from the end of a text string in Salesforce. Let’s take a scenario and understand it better:
In the Contact object, there is a field for the customer’s email address. The business requirement is to display only the email domain in a separate field.
For example, if the email address is alex@gmail.com. The new field should display gmail.com.
- Go to the Gear Icon. Click on the Setup. Select the Object Manager tab. Select the Object on which you want to create the Formula Field. Here, I’m going to create a Contact Object.
- In the Contact setup, click Fields and Relationships, then click New to create a new field.

- Select the Formula option from the data type and click Next.

- Next, provide the Field Label and API Name for the formula field. Then, in the Formula Return Type, select TEXT, and click the Next button.