+ Start a Discussion
Ron HessRon Hess 

yet another 15 charID to 18 charID function, javascript

not that you would ever need this, however it appears that the AJAX sforceClient does not like 15 charID's in Retrieve, so I ported this late last night from the java version posted elsewhere.

only tested for a short time, but it appears to work.

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;
}

 

Harish GSHarish GS
Hi ,
I am not sure, the soluation to your problem, but this example may help to get some idea using built funcation in salesforce...

CASESAFEID
Description: Converts a 15-character ID to a case-insensitive 18-character ID.
Use: CASESAFEID(id) and replace id with the object’s ID.
Example:
CASESAFEID (Id)
This formula replaces the 15-character ID with the 18-character, case-insensitive ID.
Tips:
Convert to 18-character IDs for better compatibility with Excel.
The CASESAFEID function is available everywhere that you can define a formula except reports and s-controls.
CEILING
Description: Rounds a number up to the nearest integer.
Use: CEILING(number) and replace number with the field or expression you want rounded.
Example: Rounding Up (literal value)
CEILING(2.5)
This formula returns 3, which is 2.5 rounded up to the nearest number.
Earthquake Magnitude
CEILING(Magnitude__c) returns the value of a formula number field that calculates the magnitude of an earthquake up to the nearest integer.