In this Salesforce Tutorial, we will learn how to reverse a string using the REVERSE function in Salesforce. In addition, we will learn syntax, and use cases where we can use the Salesforce REVERSE function.
One day I got a task to add a security feature for sensitive data, and to add this extra security layer to the data, I decided to reverse the text, so someone not easily guess it.
After searching, I found that to reverse a text in Salesforce, we can use the REVERSE function of Salesforce. If you want to learn how to use the Salesforce REVERSE function, to reverse the string you have come to the right place.
In this complete tutorial, we will explore how to use the REVERSE function in Salesforce Lightning and Salesforce Classic with practical examples.
What is REVERSE Function in Salesforce
The Salesforce REVERSE function is one of the several TEXT functions available in Salesforce that are used to conduct text operations on Salesforce fields.
As its name refers to REVERSE, the Salesforce REVERSE function reversed the order of the characters in a provided text string. The function takes only one argument in the REVERSE function, that is the text that we want to reverse.
Below is the syntax of the Salesforce REVERSE function:
Here, the text is the parameter that specifies the text string that we want to reverse.
Return: As a result, the REVERSE function returns the reversed string.
Let’s see a practical example of how to use the REVERSE function in Salesforce.
Suppose you are working as a Salesforce administrator and you got a task where you assign the personal locker key to each of the contacts. To make this locker number unique and confidential, you decide to reverse the first name of each contact and create this as a secret locker number so it gets easily remembered by the person.
To reverse the first name, you will decide to utilize the REVERSE function in Salesforce. Here, is the formula for the scenario:
With this, we have learned what is REVERSE function, its syntax, and its use case. Now, we will learn how to use the REVERSE function in Salesforce Lightning and Salesforce Classic one by one with an example.
How to reverse string value in Salesforce Lightning
The following are the steps to use the REVERSE function to reverse the string value in Salesforce Lightning:
Step-1: Log in to the Lightning Experience with your Salesforce account. If you are not on the lightning interface’s home page, click the “Gear” icon to the right and then select “Setup” (Setup for the current app) from the dropdown menu.
Step-2: Click on the “Object Manager” in the navigation bar after redirected to the setup for the current app in the lightning interface.
Step-3: Now, on the object manager page you will get the list of all standard and custom objects of Salesforce. Decide the item you wish to use the REVERSE function on, then search for it in the “Quick Find” box and click it when you find it.
Suppose you decided to apply the function on the “Campaign” object, so you search for it and click on it.
Step-4: In this step, you will find the “Fields & Relationships” option on the left side of the page section. Just click it. Then, as you need to reverse the string value, you need to create the formula field, by clicking on the “New” button located on the page right side.
Step-5: Once you click on the next button, you will redirected to the “Choose the Field Type” step. Select the appropriate field type here to indicate what information the custom field will include.
As I told you, you need to create a formula field to reverse the string value, so it is simple you need to choose the “Formula” field type by clicking on the radio option next to the formula.
After that, click the “Next” button to go to the next step.
Step-6: In this step, you will be on the “Choose Output Type” page. You need to first enter the “Field Label” and “Field Name” and after selecting you need to select the formula return type.
Scenario: Let’s assume you work as an event manager and use Salesforce to manage events. Your organization gives you the task of giving a unique entry code for entry into the upcoming event to all the attendees.
Therefore, you decided to enter the field label as “Entry Code” and once you click on the field name box it gets automatically filled up. After that, you choose the “Text” as the formula return type by clicking on the radio button next to the text.
Then to move to the next step, click on the “Next” button.
Step-7: You are now on the “Enter the Formula” step. Move the course of your mouse to the “Functions” section on the right side of the page. The “All Functions Categories” dropdown will appear here, select it.
You can see here the various function categories that Salesforce offers, including “Date&Time”, “Logical”, “Math”, “Text”, and “Advance”. Select the necessary function category.
As you require the REVERSE function and it is in the text category, choose “TEXT” from the drop-down menu and then select the “REVERSE” function. The function will then be added to the advance formula subtab after that you need to click the “Insert Selected Function” button under the function category.
Scenario: Let’s imagine to generate an entry code, you decided to reverse the last 5 characters of the campaign name. For this, the easiest way is the utilize the REVERSE and RIGHT functions. Below is the formula for the, given requirement:
Here, is a detailed explanation of the code:
- We use the Salesforce RIGHT() function, to extract the specified number of characters from the end of the text. In this case, I specified the text string as ‘Name’ i.e. Campaign Name, and the number of characters to be removed as 5.
- After that, we passed the extracted result of the RIGHT() function to the REVERSE() function, so that it reverses the order of characters that we extracted from the text string.
Step-8: Once you enter the formula, you need to check whether the formula is correct or has some error. For this, click on the “Check Syntax” button and if there is a mistake, an error message will appear. Otherwise, the success message will display “No Syntax errors in merge fields or functions”.
In addition, you can enter the “Description”, and “Help Text” if you want. You can also manage the blank fields. Click the “Next” button after that.
Step-9: In this step, you are on the “Establish Field-Level Security” page. Select the profiles to whom you want to grant the field-level security access to edit the above-created custom field. The field will be hidden from these particular profiles if you don’t choose any profiles.
Let’s suppose you want to grant access to all the profiles to edit the custom field, so you check the “Visible” checkbox for this. After that, click on the “Next” button and move to the next step.
Step-10: You are now on the “Add to page layouts” step. In this step, you need to choose the page layouts where you want to include the newly created custom formula field.
By default, every page layout is chosen. Uncheck the box next to the field if you do not want to include the field in this specific page layout. Then, click on the “Save” button to save the newly created formula field.
Once the formula field is created, you can use the formula field. Let’s see an example:
- Open the “Campaign” object, create a new campaign with the “Campaign Name” field and save it.
- After saving, move to the campaign details and here you will see the “Entry Code” field that shows you the result of the REVERSE function.
Let’s deeply understand this example:
Imagine you have created a campaign with the name “Winter Conference” and save it. The formula will execute and return the entry code as “ecner”. This formula effectively reverses the five last characters of the campaign name.
With this, we have learned the utilization of the REVERSE function in Salesforce Lightning. We will now proceed and learn how to return characters in reverse order using the REVERSE function in Salesforce Classic.
Return Character in Reverse Order in Salesforce Classic
The following are the steps to use the REVERSE function to return characters in reverse order in Salesforce Classic:
Step-1: Login to Salesforce using the Classic interface. If you are already logged in to the Lightning interface, select “Profile” and then click on “Switch to Salesforce Classic” from the dropdown menu.
Step-2: After successfully logging into the Salesforce Classic, click on the “Setup” option to move to the Salesforce Classic setup page.
Step-3: Once you reach the setup page, scroll down to the “Build” section on the left side of the page. After that, click on the “Customize” dropdown arrow and choose the object in which you want to use the REVERSE function of Salesforce. Then, click on the “Fields” option given under the object dropdown.
Let’s suppose you want to use the REVERSE function, in Salesforce “Product” object.
Step-4: Now, you are on the page where you may add a new custom field to the product page as well as access all the fields related to the product object. Scroll down to “Product Custom Fields & Relationships” and select the “New” button as you want to create a new field where you can reverse the order of characters.
Step-5: After clicking on the next button, you move to the “Choose the Field Type” step. From here, pick the field type that best fits your needs. As you want to use the REVERSE function in Salesforce, you need to select the radio button next to the “Formula” field type. Then, click on the “Next” button and move to the next step.
Step-6: In this step, you are on the “Choose Output Type” page. First, you should fill out “Field Label” and “Field Name”. After that, scroll down to the “Formula Return Type” section, and choose the return type for the formula field.
Scenario: Let’s suppose you are working as an administrator in a company that uses Salesforce for customer relationship management. One day you get the task of generating the product activation key and making sure that the key ensures both uniqueness and confidentiality.
Therefore, you have entered the field label “Activation Key” and the field name fills in automatically when you click the box. After this, you select the “Text” field as the formula return type by clicking on the radio button next to the text.
Now, click on the “Next” button to move to the next step.
Step-7: Once you click on the next button, you will be redirected to the “Enter the Formula” step. Now from the “Functions” section, click on the “All Functions Categories” dropdown and choose “TEXT” from the dropdown menu.
After you click on the text category, you will get the list of all the functions that are of text type, from the list of functions search for the REVERSE function and click on it.
Once you click it, you will get a button “Insert Selected Function” under the function box. With this, the function gets inserted into the advance formula subtab, replace the function parameter with the appropriate text, fields, etc. as per the requirement.
Scenario: Let’s imagine to decided to generate the product key and you decided to reverse the SKU number of the product to make the product key unique. For this, the easiest way is the utilize the REVERSE function. Below is the formula for the, given requirement:
REVERSE( StockKeepingUnit )
Here, we use the REVERSE() function of Salesforce, which is used to reverse every character of the text string i.e. StockKeppingUnit field passed to the function.
Step-8: In this step, click on the “Check Syntax” button to check whether there is any error in the formula. If there is no error, you will get the success message, otherwise, you will get the error message.
Additionally, you can enter “Description” and “Help Text” if you want and also describe “How to handle the blank fields”. After that, click on the “Next” button to move to the next step.
Step-9: Now, select the profiles to which you want to grant edit access to this field via field-level security. The field will be hidden from all profiles, if you do not add the field-level security. Let’s imagine you decided to grant edit access of this field to all the profiles via field-level security, by clicking on the “Visible” checkbox.
Step-10: In this step, you are on the “Add to Page Layout” page. Choose the page layout that should include the field. The field will not appear on any pages. If you do not select a layout.
When finished, click on the “Save” button to save the process of creating the formula field in Salesforce Classic with the REVERSE function.
Once the formula field is created, you can use the formula field. Let’s see an example:
- Open the “Product” object, create a new product with the field “Product SKU” and save it.
- Once you save it, move to the product detail page, and you will see the “Activation Key” field showing the result of the REVERSE function.
Let’s understand the example in detail.
Suppose, you have created a product with the Product SKU “PK59@78DER” and saved it. Now, the formula will execute and show the activation key “RED87@95KP”. It means the formula effectively activates a key to the product.
With this, we have learned how to use the REVERSE function to return characters in reverse order in Salesforce Classic with an example.
In a nutshell, we have learned about the Salesforce REVERSE function which returns the text string in reverse order. Moreover, we have learned the syntax and its practical examples.
In addition, we have discussed the process of how to use the REVERSE function in Salesforce Lightning and Salesforce Classic.
You may like to read the following articles:
- LEN Function in Salesforce | How to calculate length of a text string in Salesforce
- SUBSTITUTE Function in Salesforce | Replace Values in Salesforce Formula Field
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.