Recently, I worked at a multinational company that uses Salesforce to manage customer relationships. One day, I was assigned the task of converting a 15-record ID to a case-insensitive 18-record ID.
So, I have searched a lot and found that Salesforce has a built-in function named “CASESAFEID” for these types of conversions.
In this Salesforce tutorial, we will learn how to use the CASESAFEID function. In addition, we will see the syntax of the CASESAFEID function in Salesforce, along with real-world business examples.
What is the CASESAFEID() Function in Salesforce?
In Salesforce, CASESAFEID() is one of the Salesforce text functions that are used to carry out text operations.
The CASESAFEID() function is the function used to convert the 15-character case-insensitive Salesforce ID into an 18-character case-sensitive ID.
But in Salesforce Classic, this function first checks whether the input is a valid Salesforce 15-record ID. If so, it only converts to an 18-record ID. To check its validity, it checks that the ID does not begin with a capital letter.
In addition to this, if you want the function to convert only valid 15-record IDs in Salesforce Lightning, you have to contact Salesforce customer support to activate this functionality.
Moreover, converting these 18-record IDs improves compatibility with Excel. And you can also use this CASESAFEID function everywhere in Salesforce, except the Salesforce reports and s-controls.
Syntax and Usage of CASESAFEID() Function in Salesforce
The following is the syntax of the CASESAFEID function in Salesforce:
CASESAFEID(id)Here, id is the parameter whose value you want to replace with the case-insensitive 18-record ID. You can pass any of the text fields to the parameter, or you can directly pass the 15-record ID enclosed in the quotation marks.
Moreover, the parameter only accepts text-type data; if you pass any other type of data as a parameter, it will produce an error.
Let’s look at scenarios to understand the CASESAFEID function better.
Suppose we have a 15-record ID and we want to convert it. The formula’s evaluation produces a case-insensitive 18-record ID. Here, is the formula:
CASESAFEID("0012v00002T3vgc")With this, we have learned the syntax of the CASESAFEID() function with an example. And now, we will proceed and learn how to use the CASESAFEID function in Salesforce Lightning.
How to Use CASESAFEID() Function in Salesforce
The following are the steps to use the CASESAFEID() Function in Salesforce Lightning:
- 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.

- 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.

- 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 CASESAFEID() function.
- In this instance, I look for the “Account” object because I need to convert the account ID from 15 digits to 18 digits.
- Now, click the “Account” object to move to the account object page.

- On the product object page, the “Field & Relationship“ option is in the details section on the left side. Select “Field & Relationship” from the menu.
- The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the page.

- The field type page opens when you click the new button. The page contains a wide variety of field types. In this case, I chose the “Formula” field type, as I want to use the TEXT function in the advanced formula.
- Click the “Next” button to move on to the next step.

- The choose output type screen appears after clicking the next button. Enter the information now by filling out the “Field Label” and the “Field Name”, which is automatically filled in when you put the cursor on the field name. In this instance, I typed “Sensitive Account Number” into the field label.
- Choose the “Output Data Type“ for the field in which we want to store the result. In this case, I check the radio button next to the “Text” data type to return the formula result as text.
- Move to the next step by clicking the “Next” button.

- Go to the advanced formula editor and enter the CASESAFEID () function formula there. In this instance, I want to use the CASESAFEID function to convert the 15-digit record ID to 18 digits. The formula is as follows:
CASESAFEID( AccountNumber )- Here, we use the CASESAFEID() function that converts the AccountNumber from a 15-character case-insensitive ID to an 18-character case-sensitive ID.
- Click on the “Check Syntax” button to verify that the formula has no errors.
- We can define the “Description,” “Help Text,” and “Handle the empty field” if we want.
- To go to the next step, click on the “Next” button.

- In this step, establish “Field-Level Security“. Choose the profiles to which 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 in this instance. 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. If we do not select a layout, the field will not appear on any pages.
- To save the formula field, click the “Save” button.

We can use the formula field once we have created it. Let’s look at an example:
- Open the Account Tab and create a new account with the field Account Number.
- After saving it, move to the Detail Section, where the Sensitive Account Number field displays the output of the CASESAFEID function.

With this, we have understood how to use the CASESAFEID() function in Salesforce Lightning.
Conclusion
In a nutshell, we have learned what is Salesforce CASESAFEID function with its syntax and real-world business scenarios. In addition, we have learned the steps of using the CASESAFEID function in the formula field in Salesforce Lightning and Salesforce Classic.
You may like to read:
- BR() Function in Salesforce
- BEGINS() Function in Salesforce
- CONTAINS() Function in Salesforce
- GETSESSIONID() Function in Salesforce
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.