Return to Snippet

Revision: 30859
at August 24, 2010 08:39 by d3developer


Initial Code
// 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;
}

Initial URL

                                

Initial Description

                                

Initial Title
Chuck Tomanek convert 15 character ID Strings to 18 chars

Initial Tags

                                

Initial Language
Other