Posted By

Xhitman on 09/03/10


Tagged

Apex salesforce


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dotNetkow


Salesforce Convert 15-char to 18-char IDs in Apex


 / Published in: Other
 

URL: http://apex-lang.googlecode.com/svn/trunk/eclipse-project/src/classes/SystemUtils.cls

Credits to apex-lang package

  1. global static String to18(String the15charID){
  2. //a0BA0000000L2ZC => a0BA0000000L2ZCMA0
  3. //the15charID = 'a0BA0000000L2ZC'
  4. final String BASE ='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456';
  5.  
  6. the15charID = StringUtils.trim(the15charID);
  7. if(StringUtils.length(the15charID) != 15){
  8. return the15charID;
  9. }
  10. String result = '';
  11. List<String> chars = null;
  12. for(integer i = 0; i < 3; i++){
  13. chars = StringUtils.toCharArray(StringUtils.reverse(the15charID.substring(i*5,i*5+5)));
  14. String binary = '';
  15. for(String ch : chars){
  16. binary += Character.isUpperCase(ch) ? '1' : '0';
  17. }
  18. result += StringUtils.charAt(BASE,NumberUtils.parseInt(binary,2));
  19. }
  20. return the15charID + result;
  21. }

Report this snippet  

You need to login to post a comment.