Home » Misc
Category Archives: Misc
Ever wondered what this long string of characters called the Salesforce ID means? How is it built? Will we ever run out of IDs? This post will dive into that!
What is a Salesforce ID and what is it composed of?
In simple terms, a Salesforce ID is an identifier to a Salesforce record. As you know, Salesforce has Objects, like Account, Contact, Opportunity, Case, Custom Objects, etc… These are equivalent to Database tables: they are composed of different fields, or columns in Database terms, and records, or rows in Database terms. Each one of these row has a unique identifier: this is the ID! As an example the Account object:
On top of records, the ID can be used to reference metadata elements, like Group, Queue, Record Type…etc. So, for example, whenever you create a Queue, guess what is associated to it? A Salesforce ID.
Each ID is either a 15-character case-sensitive string, or an 18-character case-insensitive string. Let’s start by how a 15-character ID is composed:
Each one of the 15 characters can be:
- A lowercase letter (a-z) – that is 26 possibilities
- An uppercase letter (A-Z) – that is 26 possibilities again
- A Number (0-9) – that is 10 possibilities
That would give us a total of (26 + 26 + 10 = 62) possibilities for each character, therefore the ID is a base-62 string.
Now, let’s talk about the different components of the ID. To do that, we will use the above Account record ID:
Which we can divide into these distinct parts:
001 55 0 0000WO1Zi AAL
Here’s the meaning of each part:
|char 1-3 (3 chars)||001||Key Prefix|
|char 4-5 (2 chars)||55||Instance|
|char 6 (1 char)||0||Reserved|
|char 7-15 (9 chars)||0000WO1Zi||Unique identifier|
|char 16-18 (3 chars)||AAL||Case-insensitivty checksum|
- Key Prefix (3 characters): Determines the type of record. With the first 3 characters, you can know which type this ID belongs to! For example, when you read 001, this is an Account ID, 005 is a User ID, 006 is an Opportunity, 00Q is a Lead, 500 is a Case, etc…
- Instance (2 characters): Determines the Instance or server on which the record has been created on. For example, I just created an Account on my developer org, which is hosted on the instance UM3, the 4th and 5th characters of this Account were 4H, which means that 4H idetifies the UM3 instance. Note that a while back, only the 4th character was used to identify the originating Instance, and the 5th was reserved, but think of what happens when Salesforce was about to get 62 Instances? Clearly a single character was not sufficient to identify the originating Instance anymore, hence the use of the 5th character in addition to the 4th. That would give a theoretical max of 62^2 = 3,844 possible Instances.
- Reserved (1 character): Reserved for future use! Would Salesforce ever tun out of instance identification with 2 characters? You never know! (I did the math, if we add the 3rd character to the Instance identifier, that would give a whoping 238,328 possible Instance identifications).
- Unique identifier (9 characters): this is what identifies the record, and the possible combinations is HUGE: 62^9 possible combinations, to be precise 13,537,086,546,263,552!
- Unique identifier (3 characters): Used to allow for an ID to become case insensitive. Why we need this? Well, imagine working with applicaitons like Access which do not recognize that 50130000000014c is a different ID from 50130000000014C, an 18-digit, case-safe version of the ID was introduced. The case-insensitive ID is identical to the 15-character case-sensitive ID, but with these 3 extra characters appended to indicate the casing of each of the original 15 characters. This way, 18-character IDs can be safely compared for uniqueness by case-insensitive applications. Here is a way to convert 15-char to 18-char IDs. And here’s a website for the same. Are you interested to know the technical details of how these 3 characters are calculated? Check this page!
Some Record ID Key Prefixes
Here are some Key Prefixes. Next time you read an ID that starts with 001, know this is an Account ID!
Determine the record type using some code:
Finally, here is a tiny code snippet that can be used to get the record type from the ID. You can invoke it from any class, or from Anonymous Apex:
// Sample Id Id myID = '00561000000Mjya'; System.debug('This record is a '+ myID.getsobjecttype()); // Output is: "This record is a User"