October 30, 2016 by LanceShi
1.2 What is Salesforce Id and why do we have two sets of Ids in Salesforce
The concept of Salesforce Id
For each record in Salesforce, there is an identical Id assigned. For example, in our below image, a002800000lTUxo is the dedicated Id for Merchandise Book.
In Apex perspective, Salesforce Id is default to Id type. Id is a primitive type which can be converted into String. It is the unique identifier and primary key of each record in Salesforce.
The interesting part of Salesforce Id is, for each record, it has too versions of Ids – The 15 digit one and the 18 digit one. The 15 digit one is the first 15 characters of the 18 digit Id. So why does Salesforce need two parallel set of Ids?
The differences of 15 digit Id and 18 digit Id
The 15 digit Id is case sensitive. But 18 digit Id is not case insensitive. It is just case safe. This might be confusing.
In short, 15 digit Id is widely used inside Salesforce. And it is case sensitive. So records with Id ‘ABCD’ and ‘Abcd’ are considered as two different records in Salesforce perspective. If considered in case sensitive perspective, the 15 digit Id is identical. However, It is not identical in case insensitive perspective, which means, records ‘ABCD’ and ‘Abcd’ can both exist in the same Salesforce org.
Since there are external systems which are case insensitive, Salesforce prepared another set of Id for this usage – which is the 18 digit one. It is not case insensitive, but it is case safe, which means even if they are put into an case insensitive environment, they are still identical.