Skip to content

Instantly share code, notes, and snippets.

@tpitale
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/3e2659983d06d8e8c7fc to your computer and use it in GitHub Desktop.
Save tpitale/3e2659983d06d8e8c7fc to your computer and use it in GitHub Desktop.
Javascript from salesforce id converter to add suffix characters.
function convertId(id) {
if (id == null) return id;
id = id.replace(/\"/g, '');
if (id.length != 15) {
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment