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

While working as a Salesforce administrator, I was tasked with assigning ratings to leads based on their lead score.

As a solution, I found that Salesforce provides a function named ASCII, which helped me assign ratings to leads based on their lead score.

In this tutorial, we will learn how to use the ASCII() function in Salesforce to get the first character’s ASCII code from the given string as a number. We will also learn its syntax and a few real-world business-related useful examples.

What is the ASCII() Function in Salesforce?

As we all know, in the computer world, ASCII (American Standard Code for Information Interchange) is a commonly used character encoding system that assigns each character in the English alphabet, as well as numerals and other symbols, a unique numeric value.

In Salesforce, the ASCII() function is one of the text functions available for performing text operations. In basic terms, the ASCII() function is used when we need to get the numeric representation of the first character’s code point from the given string.

In addition, the ASCII function assigns values 97-122 to lowercase letters a-z, and similarly, uppercase letters A-Z are assigned values 65-90. Moreover, the digits 0-9 are defined by the values 48-57, respectively. And each symbol also has its unique code point, or, you can say, numeric value.

Syntax and Usage of the ASCII() Function in Salesforce

The syntax of the ASCII() function in Salesforce is as follows:

ASCII(value)

Here, the value parameters specify the value or field for which we want to return the numeric representation or code point of the first single character of the string.

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

IF(
    ASCII(TEXT(Lead_Score__c)) >= 62 &&    ASCII((TEXT(Lead_Score__c)) <= 78,
    "Hot",
    "Warm"
)

Suppose we have a lead score value of “W8933”. Here, the ASCII value of the first character, “W”, is 87. And 87 does not fall within the range 62-78. Therefore, the lead rating is set to “Warm”.

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

Use the ASCII() Function in Salesforce

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

  1. Click on the “Gear Icon”. Then, go to the “Setup“.
ASCII Function in Salesforce
  1. On the Setup Page, click on the “Object Manager“.
ASCII Function in Salesforce Example
  1. Select the object on which you want to create the formula using the ASCII() function. You can also search for the object.