REVERSE() Function in Salesforce [Syntax & Real Examples]

In a company, order numbers are stored in a format like ORD-458921. The manager wants to create a short tracking code using only the last three digits of the order number.

However, Salesforce formulas cannot directly read text from right to left. To solve this, you can use the REVERSE() function.

First, reverse the order number so the last digits come to the front, then use the LEFT() function to pick the first three characters, and finally reverse it again to get the correct digits.

This way, from ORD-458921, you can easily extract 921 using a formula, which would otherwise be difficult to achieve.

In this article, we will learn about how to use the REVERSE() function in Salesforce with practical examples.

What is the REVERSE() Function in Salesforce?

The Salesforce REVERSE() function is one of several TEXT functions available in Salesforce that perform text operations on fields.

As its name refers to REVERSE, the Salesforce REVERSE function reverses 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:

REVERSE(text)

Here, the text parameter specifies the string we want to reverse.

How to REVERSE() Text Value in Salesforce

The following steps show how to use the REVERSE function to reverse a string value in Salesforce.

  1. Click the Setup icon in the top right corner of the page to access Salesforce Setup.
    • Select Object Manager from the nav bar.
REVERSE() Function in Salesforce
  1. Select the object in which you want to create the formula field to reverse the text value. Here I have selected the Campaign object.
How to reverse string in Salesforce Lightning Example
  1. Select Fields & Relationships. Next, select New.
Salesforce REVERSE Function Lightning
  1. Select Formula“ as the field type. Click Next to proceed.
Salesforce REVERSE Function Lightning Example
  1. Enter Field Label: Entry Code (the Field Name auto‑fills), and choose Text as the return type, then click Next.
REVERSE Function in Salesforce Example
  1. In the formula editor, choose TEXT from the function category and insert the REVERSE function.
REVERSE(RIGHT(Name, 5))

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 result of the RIGHT() function to the REVERSE() function, so that it reverses the order of the characters we extracted from the text string.
  1. Click Check Syntax to confirm there are no errors.
    • 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.
REVERSE Function in Salesforce
  1. Select the appropriate field’s security levelthen check the box beside ‘Visible’ to make it visible to everyone. Click Next.
REVERSE Function in Salesforce Lightning
  1. Select the Page Layout Name for which the formula field is to be stated. Click Save to save the formula field.
REVERSE Function in Salesforce Lightning Example

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, go to the campaign details; there you will see the “Entry Code” field, which shows 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 last five characters of the campaign name.

How to reverse string in Salesforce Lightning

With this, we have learned how to use the REVERSE() function in Salesforce.

Conclusion

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.

You may like to read the following articles:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.