+ Start a Discussion
Mrunali GaonkarMrunali Gaonkar 

Unique 6 digit code generation for web to lead


following code is to generates 6 digit unique code i.e  strPassword  for web to lead using Lead Id and datetime value.This is working fine on sandbox as we create single record at a time.But what is probability that this following logic can fail on production??????? Code generated will be unique across or need to take some precaution to avoid errors.
// for loop over lead
strForEncryption =  String.valueOf(oLead.id) + String.valueOf(Datetime.now().formatGMT('yyyy-MM-dd HH:mm:ss.SSS')); 
blobHashCode = Crypto.generateDigest('MD5', Blob.valueOf(strForEncryption));
strHexDigest = EncodingUtil.convertToHex(blobHashCode);
strPassword = strHexDigest.substring(0,6);
SonamSonam (Salesforce Developers) 
Is strPassword only for leads coming from web? or all the leads entered in the system? If yes, you need to bulkify the code such that it can accomodate bulk leads :