Every Salesforce record has one ID that can be written two ways. The 15-character form is case-sensitive: 001A0000006Vm9r and 001a0000006vm9r are different records. The 18-character form adds three characters that encode the casing, so it stays unique even in systems that ignore case.
When the difference matters
- Spreadsheets.
VLOOKUPandXLOOKUPcompare text without regard to case, so two different 15-character IDs can match each other. - External databases and integration tools that use case-insensitive comparisons or collations.
- Reports and list views in Salesforce Classic, and some URLs, show 15 characters, while every API returns 18.
- Comparing IDs as text in Apex. An
Idvariable treats both forms as equal, but twoStringvariables holding the two forms are not equal.
What is inside an ID
The first three characters are the key prefix, which identifies the object type: 001 is Account, 003 is Contact, 005 is User, 006 is Opportunity, 00Q is Lead and 500 is Case. Custom objects get a prefix that is assigned per org. The rest identifies the Salesforce instance and the record itself.
The algorithm, step by step
- Split the 15 characters into three groups of five.
- In each group, write 1 for an uppercase letter and 0 for anything else.
- Read each group’s five bits from right to left as a binary number between 0 and 31.
- Look that number up in the 32-character alphabet
ABCDEFGHIJKLMNOPQRSTUVWXYZ012345. - Append the three resulting characters to the original ID.
Take 001A0000006Vm9r. The groups are 001A0, 00000 and 6Vm9r.
001A0 → bits 0 0 0 1 0 → reversed 01000 → 8 → I
00000 → bits 0 0 0 0 0 → reversed 00000 → 0 → A
6Vm9r → bits 0 1 0 0 0 → reversed 00010 → 2 → C
001A0000006Vm9r + IAC = 001A0000006Vm9rIACThe suffix can repair lost casing
Because the last three characters record exactly which letters are uppercase, an 18-character ID that has been forced to upper or lower case can be restored. That is useful when a spreadsheet or a legacy system has flattened a column of IDs.
Doing it inside Salesforce
- In a formula field,
CASESAFEID(Id)returns the 18-character form. - In Apex, assigning a 15-character string to an
Idvariable and converting it back withString.valueOfgives 18 characters. - Data Loader and the APIs always export 18 characters.
The checksum describes letter casing only. A well-formed ID is not proof that a record with that ID exists in any org.