/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// http://www.sundog.net/sunblog/posts/a-handy-method-for-converting-15-character-id-strings-in-salesforce-to-18-c/ public string generate18CharId(string id){ // This method will take a 15 character ID and return its 18 character ID: if (id == null){ return null; } if (id.length() != 15) { return null; } 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); } } return id + suffix; }