In this Salesforce tutorial, we will learn the steps of using the CASESAFEID function in Salesforce. In addition to this, we will see the syntax of the CASESAFEID function in Salesforce and also real-world business-related examples.
Recently, I was working in a multinational company that uses Salesforce for managing relationships with customers. One day I got an assignment to convert the 15-character ID to a case-insensitive 18-character ID.
So, I have searched a lot and found that Salesforce has a built-in function named “CASESAFEID” for these types of conversions. If you want to learn how to use the CASESAFEID function in Salesforce Lightning and Salesforce Classic component with real-life industry examples, let’s dive into this article.
What is CASESAFEID() Function in Salesforce
In Salesforce CASESAFEID() function is one of the Salesforce text functions that are used to carry out the 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 the Salesforce Classic, this function first checks that wheater it is a valid Salesforce 15-character ID, if it is then it only converts to an 18-character 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-character IDs in Salesforce Lightning, you have to contact Salesforce customer support to activate this functionality.
Moreover, the conversion of these 18-character IDs gives us better 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
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-character ID. You can pass any of the text fields to the parameter or you can directly pass the 15 character id enclosed in the quotation marks.
Moreover, the parameter only accepts the text type data, if you pass any other type of data as a parameter, it will produce an error.
Let’s look at the scenarios, for a better understanding of the CASESAFEID function.
Suppose, we have a 15-character ID and we want to convert it. The evaluation of the formula produces a case-insensitive 18-character ID. Here, is the formula:
CASESAFEID("0012v00002T3vgc")
With this, we have learned the syntax of the CASESAFEID() function with the example. And now, we will proceed and learn how to use the CASESAFEID function in Salesforce Lightning.
Read CONTAINS() Function in Salesforce
How to use CASESAFEID() Function in Salesforce Lightning
The following are the steps to use the CASESAFEID() Function in Salesforce Lightning:
Step 1: Log in to the Salesforce account and if you are in the classic modem switch to Salesforce Lightning mode first.
Step 2: Click on the “Gear” icon given on the top right side of the page and from its dropdown, click on the “Setup” option to go to the main home screen page of Salesforce Lightning.

Step 3: Now you are on the Salesforce setup page, here move to the navigation bar and click on the “Object Manager” option.

Step 4: After clicking on the object manager option, it shows up the list of all the standard and custom objects of the salesforce. In the “Quick Find Search” bar search for the object in which you want to use the “CASESAFEID” function.
Step 5: After searching the object, you will get the filtered list of the objects based on your search. It’s time to click on the object that you have searched. In my case, I searched and click on the “Accounts” object.

Step 6: You are now on the account object page, move to the left side of the page, and here in the Detail Section you will get an option of “Field & Relationship”. Click on it.
Step 7: It redirects you to the field and relationship page of the account page, click on the “New” button at the top of the page as we are going to create a new field that converts the Account Number to the case-insensitive 18-character ID.

Step 8: After you click on the “New” button, you will get multiple types of fields. Choose the “Formula” field type, as I want to use the CASESAFEID function in the formula.
Step 9: To move to the next step, click on the “Next” button on the right side of the page.

Step 10: In this step, you have to fill up the information about the new field that you are going to create. Here, I fill up the “Field Label” as Sensitive Account Number, and the “Field Name” automatically fills up as you enter the field label.
Step 11: Scroll downwards, and now you have to choose the “Output Data Type” for the field in which you want to store the resultant output. Here, I tick on the radio button next to the “TEXT” data type as I want to get the result in the text format.
Step 12: Click on the “Next” button to proceed to the next step.

Step 13: In this step, it redirects you to the page where you have to create your formula as per your requirement. First, I move to the right side in the Functions Section, and from the dropdown choose the Text Categories Functions.
Step 14: After that, select the CASESAFEID function from the list of the text function and enter it in the formula editor box to create the formula. The formula is as below:
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.
Step 15: Click on the “Check Syntax” button, to verify that the formula has no errors.
Step 16: We can define the “Description” and “Help Text” as well as “Handle the empty field” if we want.
Step 17: To go to the next step, click on the “Next” button.

Step 18: Now on the setup “Field Level Security” choose the user profiles to whom you want to grant the field level security edit access to the field. If not added the field level security, the custom formula field that we have created not shows on the unselected profiles.
As I want it to be visible this custom field to all the profiles. So, I check the checkbox next to the “Visible” that is located on the top bar.
Step 19: Click on the “Next” button to proceed to the next step.

Step 20: Now, select the “Page Layout” where you want to add the custom formula field. If we do not select a layout, the field will not appear on any pages. Here, I am checking the checkbox next to each page layout.
Step 21: To save the advanced formula field with the CASESAFEID function, click on the “Save” function.

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. Now, we will move on and understand the procedure of using the CASESAFEID function in Salesforce Classic.
How to use CASESAFEID() Function in Salesforce Classic
The following are the steps to use the CASESAFEID() Function in Salesforce Classic:
Step 1: Log in to the Salesforce account first, if you are signed in the Salesforce Lightning move to the Salesforce Classic edition first.
Step 2: Now, move to Salesforce classic edition, click on the “Profile Avatar” dropdown, and select the option “Switch to Salesforce Classic” option.

Step 3: After successfully login into the Salesforce Classic component, click on the “Setup” option on the right top side of the page next to your name.

Step 4: Now, scroll down to the “Build” section, then click on the “Customize” dropdown option and get the list of all the objects of the Salesforce whether it is custom or standard. Search the object for whose field you want to use the CASESAFEID function, from the list of the Salesforce objects.
Step 5: Here, I search and click on the “Orders” object, as I want to convert the 15-character order number to the case-insensitive 18-character order number.
Step 6: After clicking on the orders object dropdown, you will get a list of various order options. From here, I click on the “Fields” option as I want to create a new formula field.

Step 7: After clicking on the fields option, the orders field page is opened. Now move to the button of the page in the section “Order Custom Fields & Relationship” and click on the “New” button to create a custom field.

Step 8: The “Choose the field type” page is opened. Choose the custom field type that will contain the specific type of information that you want to store. In my case, I check the checkbox next to the “Formula” field type as I want to create the formula that uses the CASESAFEID function of Salesforce.
Step 9: Click on the “Next” button to move the next step.

Step 10: After you click on the next button, you will redirect to the “Choose Output Type” page. Now fill out the “Field Label” and the “Field Name” that fill up automatically, as you click on the field name box. Here, I entered the Field Label as the “Secure Order Number”.
Step 11: Scroll downwards to the “Formula Return Type” section and choose the return field type for the newly created field. In this case, I check the radio button next to the “Text” output type to get the formula result in the text format.
Step 12: Click on the “Next” button, to move to the next proceeding step.

Step 13: Advanced Formula editor page is opened, on the right side of the page move to the Functions section and click on the dropdown and select the “Text” function.
Step 14: From here, you will get the list of the functions that have various text functions. Select the function that you want, I have selected the CASESAFEID function and entered it in the formula editor box.
Step 15: In this example, I want to convert the 15-character order number to the case-insensitive 18-character order number. So, I entered the formula in the “Enter Formula” box.
CASESAFEID( Order_Number__c )
Here, we use the CASESAFEID() function that converts the OrderNumber from a 15-character case-insensitive ID to an 18-character case-sensitive order number.
Step 16: Click on the “Check Syntax” button, to verify that the above-written formula is error-free.
Step 17: If your formula is error-free, fill up the “Description” and “Help Text” as well as “Handle the empty field” if you want.
Step 18: Now, click on the “Next” button to move to the next step.

Step 19: After you click on the next button, the “Field Level Security” page is opened. Choose the profiles to whom you want to grant field-level security editing access. If you have not selected the profiles the specific custom field will be hidden from all the profiles.
Here, I want to make this field visible to all the profiles, so I check the checkbox next to the “Visible” option.
Step 20: Click on the “Next” button to move to the next step.

Step 21: In this step, the “Add to Page Layout” page is opened. Now choose the page layout that must have your newly created field. If you do not select a page layout, the field would not be shown up on any pages.
Step 22: Click on the “Save” button to save the formula filed with the CASESAFEID function.

Once you have created the formula field, you can use it. Let’s see an example and see how the CASESAFEID function works.
- Open the Order Tab and create a new order with the field Order Number.
- After saving, it will redirect to the Detail Section, where you see the Sensitive Order Number field which shows the output of the CASESAFEID function.

With this, we have learned the procedure of how to use the Salesforce Classic CASESAFEID function.
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:
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.