Home Interview Questions and Answers What is the difference between a 15 digit and a 18 digit Salesforce ID

## What is the difference between a 15 digit and a 18 digit Salesforce ID?

A 15 digit Salesforce ID is case sensitive.
For Ex:  00120000001YztiABD and 00120000001YZTIABD are different.

15 Digit you can find in URL of Salesforce [ Used in UI]

A 18 digit Salesforce ID is case in-sensitive.
For Ex:  00120000001YztiABD and 00120000001YZTIABD are same.

Why do we need 18 digit IDs, because many Legacy system [ex: excel sheets] work with Case insensitive IDs and 18 Digit IDs are returned by API

1). Convert from 15 digit Salesforce ID to 18 digit Salesforce ID Using BinaryId Lookup:

Let say we have an 15 Digit ID ex: 0019000000B98de

Step1:
Divide 15 digit in 3 chunks of 5 digit each

00190 00000 B98de

Step2:
Reverse the Digit

09100 00000 ed89B

Step3:
Replace Capital letters with 1

00000 00000 00001

Step4:
Below are mentioned BinaryId Lookup

{“00000”, ‘A’} {“00001”, ‘B’} {“00010”, ‘C’} {“00011”, ‘D’} {“00100”, ‘E’}
{“00101”, ‘F’} {“00110”, ‘G’} {“00111”, ‘H’} {“01000”, ‘I’} {“01001”, ‘J’}
{“01010”, ‘K’} {“01011”, ‘L’} {“01100”, ‘M’} {“01101”, ‘N’} {“01110”, ‘O’}
{“01111”, ‘P’} {“10000”, ‘Q’} {“10001”, ‘R’} {“10010”, ‘S’} {“10011”, ‘T’}
{“10100”, ‘U’} {“10101”, ‘V’} {“10110”, ‘W’} {“10111”, ‘X’} {“11000”, ‘Y’}
{“11001”, ‘Z’} {“11010”, ‘0’} {“11011”, ‘1’} {“11100”, ‘2’} {“11101”, ‘3’}
{“11110”, ‘4’} {“11111”, ‘5’}

Step5:
Now replace the numbers with corresponding characters as per the Step4

00000 A
00000 A
00001 B

Step6:
Here we have last 3 digits AAB , suffix them with 15 digit id and you will have 18 Digit ID like below:

18 Digit ID : 0019000000B98deAAB

2). Convert from 15 digit Salesforce ID to 18 digit Salesforce ID Using Formula field:

its possible using formula field function called CASESAFEID(id) which converts 15 digit to 18 digit ID

here id – pass the 15digit Salesforce Id

3). Convert from 15 digit Salesforce ID to 18 digit Salesforce ID Using Apex Class & Visualforce Page:
VF Page:
[HTML]

[/HTML]

Apex Code:
[JAVA]
public with sharing class idConvertor {
public String inputId{get;set;}
public String outputId{get;set;}

public PageReference convert(){
outputId = convertId(inputId);
return null;
}

String convertId(String inputId){
string suffix = ”;
integer flags;
try{
for (integer i = 0; i < 3; i++) {
flags = 0;
for (integer j = 0; j < 5; j++) { string c = inputId.substring(i * 5 + j,i * 5 + j + 1); if (c.toUpperCase().equals(c) && c >= ‘A’ && c <= ‘Z’) {
flags = flags + (1 << j);
}
}
if (flags <= 25) {
suffix += ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’.substring(flags,flags+1);
}else{
suffix += ‘012345’.substring(flags – 26, flags-25);
}
}
}
catch(Exception exc){