Categories
Appunti

How Generate Unique Id (15 digit) for Salesforce

Blob b = Crypto.GenerateAESKey(128);
         String h = EncodingUtil.ConvertTohex(b);
         String guid = h.SubString(0,8)+  h.SubString(8,12) +  h.SubString(12,15);
         system.debug(guid);

Other Example

String hashString = '1000' + String.valueOf(Datetime.now().formatGMT('yyyy-MM-dd HH:mm:ss.SSS'));
Blob hash = Crypto.generateDigest('MD5', Blob.valueOf(hashString));
String hexDigest = EncodingUtil.convertToHex(hash);
system.debug('##########' + hexDigest );

Leave a Reply