1 answer

Hi Shiva,Greetings to you!Here is example to create unique id with state code.Use below code to solve your problem.And you can modify accordingly
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.Thanks and Regards,Deepali Kulshresthawww.kdeepali.compublic class CreateAutoNumber {
public static string autoNumber(){
Integer len=5;
String str = string.valueof(Math.abs(Crypto.getRandomLong()));
String randomNumber = str.substring(0, len);
String State = 'AK';
String StateCode = State + randomNumber;
system.debug('Random Number-' + randomNumber);
system.debug('StateCode-' + StateCode);
return randomNumber;
}
}