public String Convert15CharTo18CharId(String id) { 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 += '012345'.substring(flags - 26, flags - 25); } } String convertId = id + suffix; //18 Digit Id with checksum System.debug('convertId-' + convertId); return 18 digitId; }
Example:
String Id = '0019000001EJNfj'; String convertedId = Convert15CharTo18CharId(Id);