function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SheaPropSheaProp 

Record ID Passed in Custom Link/Button

For some reason, whenever I use a record ID within a custom link or button, Salesforce is passing in the 15-character ID instead of the 18-character ID. In the past, I have coded around this on my own (using case-sensitive comparisons and substrings) but I'm now running into an issue where it's not possible to use these tricks.

Why is SF only passing the 15-character ID and how do I make it use the 18-character ID?

Thanks,
Mike
Best Answer chosen by Admin (Salesforce Developers) 
khanWebgurukhanWebguru



in javascript, so you can put this into an scontrol, then the scontrol will fixup the ID and display it in a field ( by putting the scontrol on the campaign page.)

 

 

Code:
function normaliseSforceID( id) { // fluff up a 15 char id to return an 18 char id
if (id == null) return id;
id = id.replace(/\"/g, ''); // scrub quotes from this id
if (id.length != 15) {
//print('well, id is not 15, bye' + id + ' ' + id.length);
return null;
}
var suffix = "";
for (var i = 0; i < 3; i++) {
var flags = 0;
for (var j = 0; j < 5; j++) {
var c = id.charAt(i * 5 + j);
if (c >= 'A' && c <= 'Z') {
flags += 1 << j;
}
}
if (flags <= 25) {
suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(flags);
} else {
suffix += "012345".charAt(flags-26);
}
}
return id + suffix;
}

All Answers

werewolfwerewolf
Why do you need the 18-char ID?  The 15-char and 18-char IDs are equivalent and should be interchangeable.
MD13MD13
In most cases this is true. However, I am using DbAmp to query data through a SQL Linked server and it doesn't work correctly unless you substring the ID and change the coallation in order to force a case-sensitive query. I am currently working on a new query in which the workaround doesn't work very well and would prefer to just get the 18-character ID so no workaround is needed.

Mike
werewolfwerewolf
Well, there is an algorithm to convert a 15-char ID to an 18-char ID.  This article describes it well.  The code example given there is in PHP.

This discussion board post gives some Javascript sample code for performing this conversion.
khanWebgurukhanWebguru



in javascript, so you can put this into an scontrol, then the scontrol will fixup the ID and display it in a field ( by putting the scontrol on the campaign page.)

 

 

Code:
function normaliseSforceID( id) { // fluff up a 15 char id to return an 18 char id
if (id == null) return id;
id = id.replace(/\"/g, ''); // scrub quotes from this id
if (id.length != 15) {
//print('well, id is not 15, bye' + id + ' ' + id.length);
return null;
}
var suffix = "";
for (var i = 0; i < 3; i++) {
var flags = 0;
for (var j = 0; j < 5; j++) {
var c = id.charAt(i * 5 + j);
if (c >= 'A' && c <= 'Z') {
flags += 1 << j;
}
}
if (flags <= 25) {
suffix += "ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(flags);
} else {
suffix += "012345".charAt(flags-26);
}
}
return id + suffix;
}
This was selected as the best answer