I have a requirement of generating a unique 25 char alpha numeric #which has to be unique across different pods. I am using the following function.
public with sharing class GenerateUniqueKey {
private static final Integer KEY_LENGTH = 25;
public static String generateKey(){
Blob aes = Crypto.generateAesKey(128);
String randomValue = EncodingUtil.convertToHex(aes).left(KEY_LENGTH);
return randomValue;
}
}
So far, in the debug console, running it in a loop of 4071 generated unique output since the set has 4071 elements.
try{
Set<String> generateKey = new Set<String>();
for(integer i = 0; i < 4071 ; i++){
String key = GenerateUniqueKey.generateKey();
generateKey.add(key);
}
for(String s : generateKey){
System.debug(s);
}
System.debug('>>>>> length : ' + generateKey.size());
}catch(Exception e){
System.debug('>>>>> Exception : ' + e);
}
My question is does the above class guarantee unique 25 chars across pods in salesforce?
Why 4071? in loop, else maximum debug log reached.
system.assertEquals(4071,generateKey.size());
Turn down your log levels. You should be able to get a whole lot more to test