Last active
August 29, 2015 14:05
-
-
Save tpitale/3e2659983d06d8e8c7fc to your computer and use it in GitHub Desktop.
Javascript from salesforce id converter to add suffix characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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