Generate Unique String Using Apex

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 :


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: 352

Share Post

You may also like...

1 Response

  1. Shireen Khan says:

    Very helpful ! Thanks 🙂

Leave a Reply

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