Generate Random String

 DateTime currentDate = DateTime.now();

String randstring = currentDate.format('ddMMHHmmss');

Integer randomNumberToAppend = null;

while(true){

    randomNumberToAppend = Integer.valueOf(Math.random()*10000);

    if(String.valueOf(randomNumberToAppend).length()==4){

        break;

    }

}

randstring += randomNumberToAppend;


System.debug('randstring@@@'+randstring);

Comments

Popular Post

Get the record Count of all countable Sobjects in Salesforce

Roll Up Amount on Parent Object from Child Object In Lookup Relationship

Fetch record type-specific picklist values directly in Apex