+ Start a Discussion
Mrunali GaonkarMrunali Gaonkar 

Unique 6 digit code generation

Hi,
following is the code which i am writing in my lead trigger to generate password.
i am not sure this number will be unique or not.. can any 1 help..

//fetching last accesscode.
          in for loop 
                        Integer len = 6;
                        String hashString = String.valueOf(accessCode) ;
                        Blob hash = Crypto.generateDigest('MD5', Blob.valueOf(hashString));
                        String hexDigest = EncodingUtil.convertToHex(hash);
                        String pwd = hexDigest.substring(0,len);
                        system.debug('##########' + pwd );
                        oLead.Access_Code__c = String.valueOf(pwd);
                        accessCode++;