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 posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page