Dealing With 15 and 18 Character Salesforce Record IDs

Salesforce has a multi-tenant architecture and it identifies every record uniquely across all customers by assigning a unique Record ID to each record. As a Salesforce admin or developer, you need to perform data operations, write formulas and reference records using their unique Record IDs.

Salesforce provides you with two versions of Record IDs – a 15 character and an 18 character ID. The two versions are used in different situations.

  • 15 character ID  is a case-sensitive version which is referenced in the Salesforce user interface. You can use this ID while performing data operations through the user interface.
  • 18 character ID is the case-insensitive version which is referenced through the APIs. The case-insensitive ID is identical to the 15-character case-sensitive ID, but with 3 extra characters appended to indicate the casing of each of the original 15 characters. You will need this while using tools like Data loader and Workbench. The API tools will accept the 15 character IDs as input but it will always provide you the 18 character ID when you export data. It is a Salesforce best practice to use 18 character IDs in APIs, formulas or as reference due to its case insensitive nature.

You can read more about these two type of IDs here. As mentioned in the article – “Because there are applications like Access which do not recognize that 50130000000014c is a different ID from 50130000000014C, an 18-digit, case-safe version of the ID is returned by all API calls. The 18 character IDs have been formed by adding a suffix to each ID in the Force.com API. 18-character IDs can be safely compared for uniqueness by case-insensitive applications, and can be used in all API calls when creating, editing, or deleting data.”

Let us take a scenario where you are required to reconcile the data between a file extracted using an API tool and one from a Salesforce report. In this scenario, you will have a mismatch between the record Ids in both files. Wouldn’t it be nice to get the 18 character Record ID from the Salesforce user interface so that it exactly matches the ones given to the API tools? It will save you the time and effort in going into external tools and running separate queries and reports.

Follow the below given steps to convert 15 character IDs to 18 character IDs for any record:

  1. Go to Setup | Customize | Object Name | Click Fields
    • For Custom Objects: Setup | Create | Objects | Object Name
    • For Lightning: Setup | Object Manager | Object Name
  2. In the related list “Custom Fields & Relationships” click New.
  3. Click the Formula radio button.
  4. Click the Text radio button for “Formula Return Type.”  (Return type: Text)
  5. Input the following Formula into the Formula Editor: CASESAFEID(Id)
  6. Set Field Visibility at field level and also add/remove it on page layout.
  7. Click Save.

With the help of this simple formula, you will have the 18 character case insensitive ID readily available on any Salesforce record which you can leverage in your APIs & data operations.

Team Varasi

Shailesh Bhide
Shailesh Bhide
Shailesh is a Principal at Varasi. He shares thoughts and insights on technical know-how and patterns that helps us build elegant Salesforce solutions for our customers. He is passionate about leveraging the Salesforce platform to its full potential.