TEXT() Function in Salesforce | Syntax, Examples, & Use Cases

Recently, I worked at a company that used Salesforce as its CRM application. One day, I was tasked with displaying a message showing the number of days left until the subscription expires.

As a solution, I found that Salesforce provides a function named TEXT, which helped me display this text message. If you want to learn how to use the TEXT() function in Salesforce, let’s deep dive into this tutorial and learn with examples.

In this tutorial, we will learn how to use the TEXT() function in Salesforce to convert a value to text using the standard display format. We will also learn its syntax and a few real-world business-related useful examples.

What is the TEXT() Function in Salesforce

The TEXT() function in Salesforce is one of the text functions available in Salesforce and is used to perform text operations. In basic terms, the TEXT() function is used to display or modify data in a textual format.

In other words, this TEXT() function converts data from the per cent, number, date, date/time, currency, and picklist field types into a text field type.

The syntax of the TEXT() function is as follows:

TEXT(value)

Here, the value parameters specify the value or field to transform into text. It could be a constant value, a formula, or a field reference.

For a better understanding of how the TEXT function works, let’s look at an example.

As I mentioned above, I need to display a message showing the number of days left until the subscription expires. Therefore, I will utilise Salesforce TEXT() function for this. The formula is as given below:

IF(
  Subscription_Expiry_Date__c >= TODAY(),
  "Product Expired",
  "Number of Days Remaining: " & TEXT(Subscription_Expiry_Date__c - TODAY())
)

With this, we learned the syntax of the TEXT() function and an example. We’ll now look at how to use the TEXT() function in Salesforce.

Use the TEXT() Function in Salesforce

The following steps show how to use the TEXT() function in Salesforce.

  1. Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click “Setup“ from the dropdown menu to continue.
TEXT Function in Salesforce
  1. The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.
TEXT Function in Salesforce Example
  1. The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find search field to find the item on which we want to use the TEXT() function.
    • In this instance, I look for the “Product” object because I need to convert the product price to text and also concatenate the USD text to it.
      • Now, click the “Product” object to move to the product object page.