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.
- Click on the “Gear Icon”. Then, go to the “Setup“.

- On the Setup Page, click on the “Object Manager“.

- Select the object on which you want to create the formula using the ASCII() function. You can also search for the object.

- Select “Field & Relationship,” where we can view the created fields and create new ones.
- Click the “New” button to create a new Formula field.

- Choose the “Formula” field type, as we want to use the ASCII function in the advanced formula.
- Click the “Next” button to proceed.

- Enter the information now by filling out the “Field Label” and the “Field Name. In this instance, I typed “Discount Price” into the field label.

- Enter the ASCII() function formula in the advanced formula editor. In this case, I wish to utilise the ASCII function to determine the discount based on the first character of the coupon code. The formula reads as follows:
IF(
ASCII(CouponCode) >= 65 && ASCII(CouponCode ) <= 74,
Price__c * 0.3,
Price__c
)- We use the ASCII function to convert the first character of the Coupon Code field into its unique ASCII value.
- Then, we use the IF function that checks whether the first character of the Coupon Code falls within the range of 65-74, i.e. A-J.
- If so, we multiply the price by 0.3, which means a 30% discount is applied.
- If not, we get the price without any discount value.
- To check the formula and make sure there are no errors, click the “Check Syntax” option.
- Optionally, we may define the “Description” and “Help text” as well as “Handle the empty field” if we like.
- Click the “Next” button to go to the security setup for the formula field.

- In this step, establish “Field-Level Security“. Choose the profiles we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
- As I want it to be visible to all profiles, I have checked the “Visible” checkbox. After that, click the “Next” button located at the top.

- Add the custom field to the “Page Layout“ after setting up the field-level security. Pick the page layout that has this field in it. The field will not appear on any pages unless we select a layout.
- Click the “Save” button to save the formula field.

- We can use the formula field once we have created it. Let’s look at an example:
- Create a new coupon in the Coupon Tab by opening the Coupon Code and Price fields.
- Click on the Details section after that, and the Discount Price field will display the ASCII() function output.
- As a result, we now understand how to use the ASCII function in Salesforce.
Conclusion
In conclusion, we have learned the Salesforce ASCII() function. Moreover, we have learned the ASCII() function in Salesforce syntax and several real-world business scenarios.
In addition, we also covered the steps for using the ASCII() Function in Salesforce Lightning and Salesforce Classic.
You may like to read:
- TEXT() Function in Salesforce | Syntax, Examples, & Use Cases
- ABS() Function in Salesforce | Syntax, Examples, & Use Cases
- Round() Function in Salesforce | Syntax, Examples, & Use Cases
- MCEILING() Function in Salesforce | Syntax, Examples, & Use Cases
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.