As we know that each record Id represents a unique record within an organisation. There are two versions of every record Id in salesforce :
The API will accept the 15 digit ID as input but will always return the 18 digit ID.
Now how we can calculate the 18 Digit Id from 15 Digit Id :
//Our 15 Digit Id
String id = '00570000001ZwTi' ;
string suffix = '';
integer flags;
for (integer i = 0; i < 3; i++) {
flags = 0;
for (integer j = 0; j < 5; j++) {
string c = id.substring(i * 5 + j,i * 5 + j + 1);
//Only add to flags if c is an uppercase letter:
if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
flags = flags + (1 << j);
}
}
if (flags <= 25) {
suffix = suffix + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1);
}else{
suffix = suffix + '012345'.substring(flags-25,flags-24);
}
}
//18 Digit Id with checksum
System.debug(' ::::::: ' + id + suffix) ;
- 15 digit case-sensitive version which is referenced in the UI
- 18 digit case-insensitive version which is referenced through the API
The API will accept the 15 digit ID as input but will always return the 18 digit ID.
Now how we can calculate the 18 Digit Id from 15 Digit Id :
//Our 15 Digit Id
String id = '00570000001ZwTi' ;
string suffix = '';
integer flags;
for (integer i = 0; i < 3; i++) {
flags = 0;
for (integer j = 0; j < 5; j++) {
string c = id.substring(i * 5 + j,i * 5 + j + 1);
//Only add to flags if c is an uppercase letter:
if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
flags = flags + (1 << j);
}
}
if (flags <= 25) {
suffix = suffix + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags,flags+1);
}else{
suffix = suffix + '012345'.substring(flags-25,flags-24);
}
}
//18 Digit Id with checksum
System.debug(' ::::::: ' + id + suffix) ;
No comments:
Post a Comment