Demystifying and converting 15 and 18 character Salesforce IDs
When working with Salesforce you’ll come across your record’s IDs at some point in time. When having a closer look, you’ll notice that there is a 15- as well as an 18-character version for the same record. Why is that and how can you convert them? It is easy and can be done in different Salesforce Clouds, Excel, your own progams and even online directly within this blogpost! Check it out!
Differences between the 15 and 18-character IDs
It might seem weird to you that two different IDs identify the same record. But if you take a closer look, you’ll see that the first 15 characters are the same for these IDs. So what are the additional characters for?
They’ve been introduced to ensure the ID is case-insensitive and can also be used in systems and tools where case sensitivity isn’t given. So if you mix up lowecase and uppercase characters in the short version of an ID you’ll get in trouble as you’ll possibly find youself looking at a different record or an error message.
When to use which ID?
If you don’t know whether a system or tool you are working with is case-sensitive or not, you can always go with the longer version of an ID. The standard API also retuns the 18-character ID at all times. In case you use Marketing Cloud in combination with the CRM, you might already know that it also uses the 18-character ID for your subscribers.
However, in some places you can only get the 15-character version. For example when exporting a report or displaying an ID somewhere. That might also be the case if you get the information from a different tool that has been integrated into the IT landscape with the short IDs only.
So how can you convert an ID?
Within the Salesforce Platform there are functions to get the 18-character representation when given the short version. This can be done using a formula field and the
CASESAFEID-function in the CRM or using AMPscript and the
LongSFID-function in Marketing Cloud:
Below, you’ll find an online converter as well as the necessary steps to add the function to an Excel spreadsheet!
Convert an ID online
If you just want to convert a single ID manually, you can use the form below and do the conversion directly within your browser:
You want to find out how it works?! Find out below the excel section of this post or review the code on GitHub.
Microsoft Excel version
In order to use the conversion function in Microsoft Excel, just follow these six simple steps:
Adding the sf15to18-function to Excel
- Open or create a spreadsheet in Excel
- Go to Tools > Macro > Visual Basic Editor
- Right click on This Workbook and select Insert > Module
- Copy and paste the contents of
sf15to18.bas(see below) to the editor
- Save the macro
- Use it in your spreadsheet. If you want to convert the value of Cell B1, you need to use the following formula for example:
How it works
Getting the case insensitive 18-character ID is an easy process which basically works like this:
- The 15-digit ID is split into three 5-character segments.
- Each of these segments is then reversed.
- Every uppercase letter is replaced with a 1, every other character with a 0.
- The three suffix-digits for the Id can then be looked up in a table, segment by segment (first segment gives the first digit, etc.). The table below shows an excerpt of such a table, which can be easily completed.
|segment result||suffix digit|