Today I want to share some information regarding Salesforce record Ids.
Each record in Salesforce has a unique record id. Record ids are either 15 or 18 characters in length and each character is base 62 encoded which means a character can be the numbers 0-9, lower case letters a-z, or capital letters A-Z. That means there are 6215 or 768,909,704,948,766,668,552,634,368 possible record ids.
Object and Pod Info Encoded into Ids
The first three characters of an Id identify the object and are the same across orgs. For example, 001 is the prefix for account records. See Daniel Ballinger’s Obscure Salesforce object key prefixes Post for a thorough reference of them all. That means a Salesforce org can have 238,328 standard and custom objects in it. Would be interesting to see what happens if someone tried to create that many objects in an org.
The fourth and fifth digits identify the Salesforce pod or datacenter where the record was created. The fourth one is the primary identifier but if needed, the fifth digit is used. The 6th digit is reserved and currently not in use so it is 0 for now. The last 9 are a really big number to help identify the record. That means for any given object, there are 629 or 13,537,086,546,263,552 possible records it can hold.
For more info, check out the What are Salesforce Ids composed of StackExchange post.
18 Digit Id Case-Insensitive for Comparison Only
One can take a 15 digit record id, apply an encoding algorithm to it, and make it into an 18 digit id. Why would one do that you’re probably thinking… Well, certain external programs may treat 001E000001LaoNK and 001E000001LaoNk as the same value when comparing them even though they’re different. Did you notice the difference? To solve this, Salesforce provides the 18 digit version of the Salesforce record ids when querying through the APIs so that external programs don’t run into this issue.
Given the above and reading various documentation, some people think that the 18 digit ids are case-insensitive so one can simply upper case or lowercase everything and the ids will still work in Salesforce. This is false. It’s only true when comparing two Salesforce record Ids that haven’t been altered.
Easily Open a Record Using Just Its Id in Classic
Have only a Salesforce record id and want to open it? Open Salesforce Classic, paste the record id after the domain in your browser’s url and it should open the record. For example, if my org’s domain is https://cs13.salesforce.com, I can open a record by using https://cs13.salesforce.com/<record_id_here>.
Unfortunately, this doesn’t work in Lightning experience. If there’s another way to do it, please let me know!
Query Polymorphic Relationships For A Particular Object using SOQL
Some standard objects have a polymorphic relationship which means they can be tied to any parent object. For example, an activity record’s What Id field. There are times when you’d like to use SOQL to query activity records for a particular object. Unfortunately, Salesforce doesn’t allow the “like” keyword to be used with Id fields so you can’t do something like this:
BUT you can use greater than and less than operators with Ids. This means you can select all activities tied to a given object by comparing the ids greater than or equal to the object’s minimum record id value and less than or equal to the object’s maximum id value. For example, let’s say we wanted to query all the account tasks. That can be done like this:
What other information do you have on Ids?