Return to Snippet

Revision: 31366
at September 3, 2010 12:55 by Xhitman


Initial Code
global static String to18(String the15charID){
        //a0BA0000000L2ZC  => a0BA0000000L2ZCMA0
        //the15charID = 'a0BA0000000L2ZC'
        final String BASE ='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456';

        the15charID = StringUtils.trim(the15charID);
        if(StringUtils.length(the15charID) != 15){
            return the15charID;
        }
        String result = '';
        List<String> chars = null;
        for(integer i = 0; i < 3; i++){
            chars = StringUtils.toCharArray(StringUtils.reverse(the15charID.substring(i*5,i*5+5)));
            String binary = '';
            for(String ch : chars){
                binary += Character.isUpperCase(ch) ? '1' : '0';
            }
            result += StringUtils.charAt(BASE,NumberUtils.parseInt(binary,2));
        }
        return the15charID + result;
    }

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

Initial Description
Credits to apex-lang package

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

Initial Tags

                                

Initial Language
Other