Convert Salesforce Ids from 15 to 18 characters using Javascript
I figured this will be useful for anybody working with Salesforce. I used this within Netsuite and worked beautifully. Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function convertSFDC15To18(sfdcID15){ if (sfdcID15.length == 15) { var s = ""; for (var i = 0; i < 3; i++) { var f = 0; for (var j = 0; j < 5; j++) { var c = sfdcID15.charAt(i * 5 + j); if (c >= "A" && c <= "Z") f += 1 << j; } s += "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".charAt(f); } return sfdcID15 + s; } else { throw "Error : " + sfdcID15 + " has not a length of 15 characters. Current length detected: " + sfdcID15.length + " characters."; } } //Example: var sfdc18 = convertSFDC15To18('5003000000D8cuI'); // Returns 5003000000D8cuIAAR |