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
thechadthechad 

display 18 character ID in Page Layout

I am trying to display the 18 character key for campaigns in the campaign layout using a formula field for easy access to the full key, but using "Id" in the formula field only returns the 15 character key.

Can someone help me here?

Thank you in advance.
Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess
looks like this has not been posted for a few weeks, so here you go

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

Ron HessRon Hess
looks like this has not been posted for a few weeks, so here you go

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
thechadthechad
Does this return the actual sfdc 18 character id?  It looks like the code generates a random set of 3 aditional characters... 

Thank you for the reply.

~Chad
Ron HessRon Hess
yes, actual 18 char id is determined completely by the 15 char id.

The 3 extra chars are a check sum of the capitalization of the chars in the 15 char id.

it's deterministic, an algorithm if you will.  :smileywink:
SnardSnard
I have seen this fix (or variations of it) posted previously. I've had the same need, where I need to pass an 18 character ID to an existing integration which stores (and expects) the longer IDs. In a specific case, I wanted to pass the value of the merge field {!User.Id} to an external integration which expected the full 18 character ID. I came up with a 1-line way to do this using the AJAX API:

var SFDCUserID = sforce.connection.query("Select Id from User where Id ='{!User.Id}'").getArray("records")[0].Id;

Of course this consumes an API call, but it seems to work well.

I wonder if anyone has yet suggested adding merge field options to specify the full 18 character values (i.e. {!User.Id__f})



Message Edited by Snard on 10-25-2007 10:42 AM

SimplySfdcSimplySfdc
this is confirm works. Thanks
ezradataezradata

I say, implement the 15-to-18-char conversion in a formula field and circumvent code entirely: http://tinyurl.com/15CharFix

 

Id & 
MID( 
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345", 
    MIN(FIND(MID(Id, 5, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 16 + 
    MIN(FIND(MID(Id, 4, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 8 + 
    MIN(FIND(MID(Id, 3, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 4 + 
    MIN(FIND(MID(Id, 2, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 2 + 
    MIN(FIND(MID(Id, 1, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 1 + 1, 
    1) & 
MID( 
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345", 
    MIN(FIND(MID(Id, 10, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 16 + 
    MIN(FIND(MID(Id, 9, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 8 + 
    MIN(FIND(MID(Id, 8, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 4 + 
    MIN(FIND(MID(Id, 7, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 2 + 
    MIN(FIND(MID(Id, 6, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 1 + 1, 
    1) & 
MID( 
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345", 
    MIN(FIND(MID(Id, 15, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 16 + 
    MIN(FIND(MID(Id, 14, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 8 + 
    MIN(FIND(MID(Id, 13, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 4 + 
    MIN(FIND(MID(Id, 12, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 2 + 
    MIN(FIND(MID(Id, 11, 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1) * 1 + 1, 
    1)

 

NikuNiku

Nice one

Merry SMerry S

Thanks, this was just what I needed today. :)

Ezra @ BazaarvoiceEzra @ Bazaarvoice

Whoops! The big, fancy formula field is no longer needed; now you can just use the CASESAFEID() formula function.