Last active
September 23, 2016 18:40
-
-
Save scolladon/16f37a1b9c4e512e976475d51872ee2d to your computer and use it in GitHub Desktop.
Apex ID 15 to 18
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
public static string generate18CharId(final string id){ | |
final String abecedair = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'; | |
if (String.isBlank(id) || (id.length() != 15 && id.length() != 18)) { | |
return null; | |
} | |
if (id.length() == 18) { | |
return id; | |
} | |
string suffix = ''; | |
for (integer i = 0; i < 3; i++) { | |
integer flags = 0; | |
for (integer j = 0; j < 5; j++) { | |
string c = id.substring(i * 5 + j,i * 5 + j + 1); | |
if (c.isAllUpperCase() && c >= 'A' && c <= 'Z') { | |
flags += (1 << j); | |
} | |
} | |
suffix += abecedair.substring(flags,flags+1); | |
} | |
return id + suffix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment