Salesforce IDs are actually comprised of several pieces of data and can come in 15 or 18 character varieties. The difference is that the 18-character flavor has a suffix that will render them case-insensitive. From time to time, you have come across a data extract or something that contains the 15-digit variety and have a need to convert them to 18-digit IDs.
For more information about just what is included in a Salesforce ID, checkout this post:
If you don't care to dig into the details and just want a handy online converter, here ya go:
- First we need to divide the 15-character ID into 3 groups of 5 characters.
- Now we need to reverse the order of each set
For each set of characters, we will create a new set of bits (
0s). Then for each character, we will add a
1to the corresponding set of bits, if the character is an uppercase letter, or a
0if the character is a lowercase letter, or a number.
The previous step actually converted each character set into a number, in binary. Now we need to convert each binary number to a decimal number. This should leave us with 3 numbers that could range from
Now we will need to construct a collection of character that will include uppercase letters from
Z, and the numbers
5, as follows:
The last step here is to look at our 3 numbers, and find the character in the collection we just created at the index of each number. The index is zero-based so
B, and so on. The result of this operation should leave us with 3 character.
And there's your suffix! 🎉
Simply tack it on to the end of the original ID
Need a code example?