salesforce

Requirement : Generate Unique String Using Apex

In This Post I will tell you how you can generate a unique string by using apex.

Here We have a class name : GenerateRandomString used to generate inique  random string

here is the class example :

GenerateRandomString

public class GenerateRandomString
 {
    public static string word()
    {
       final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
       String guid = '';
       while (guid.length() < 5) {
       Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
       guid += chars.substring(idx, idx+1);
      }
    return guid;
   }
 
 }

hope this will help you …

Hits: 1007

Share Post

By Sneh Verma

My Name is Himanshu Rana, 23 Years young, born and grow up in Ghaziabad, India. A High Spirited Salesforce Admin, Developer and a Blogger. I currently work at Wakencode Technologies,

One thought on “Generate Unique String Using Apex”

Leave a Reply

Your email address will not be published. Required fields are marked *