Salesforce IDs Explained (UPDATED)

Everything you ever wanted to know about Salesforce IDs and then some.

Salesforce IDs Explained (UPDATED)

This article has been updated to reflect the changes made in Salesforce's Summer '23 release. Salesforce now uses 3 digits for the Instance ID, rather than 2. This seems to be connected to the implementation of Hyperforce. You can read more about this change here.

The Anatomy of a Salesforce ID

To the untrained eye, a Salesforce ID might seem like a random collection of numbers and letters. However, if you have been around Salesforce for even a short while, you will start to see some patterns. Salesforce IDs are, in fact, made up of district parts. See the infographic below:

Anatomy of a Salesforce ID Infographic

Object Prefix

id-parts_part1-1

The first 3 characters tell us which SObject type the record is. Most SObjects that users interact with, both standard and custom, have a prefix. In nearly every case, standard objects will have the same prefix in every org. Here are some examples:

SObject Name Prefix
Account 001
Contact 003
Opportunity 006
Lead 00Q
Case 500
User 005

But rather than trying to memorize all these "magic codes", here are a couple of ways to find out all the prefixes in your org, including custom objects, which will obviously be org specific.

Getting SObject Prefixes:

Using Apex

Here is an almost one-liner to print all of your org's SObjects and their respective prefixes to the debug console:

id-parts-updated_part2

If you would like to take a deep dive into the algorithm, I've got a post about that:

Final Thoughts

I hope this has helped educate and clear up any misconceptions about Salesforce IDs. If I left anything out, or something was unclear, please let me know in the comments below. Thanks!