Skip to content

15 vs 18 character Salesforce IDs, and how the conversion works

Why Salesforce has two ID lengths, when you need the 18-character form, and a worked example of the checksum algorithm.

5 minute readUpdated By Kappa Vinay

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. VLOOKUP and XLOOKUP compare 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 Id variable treats both forms as equal, but two String variables 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

  1. Split the 15 characters into three groups of five.
  2. In each group, write 1 for an uppercase letter and 0 for anything else.
  3. Read each group’s five bits from right to left as a binary number between 0 and 31.
  4. Look that number up in the 32-character alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ012345.
  5. Append the three resulting characters to the original ID.

Take 001A0000006Vm9r. The groups are 001A0, 00000 and 6Vm9r.

Example
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  =  001A0000006Vm9rIAC

The 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 Id variable and converting it back with String.valueOf gives 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.