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
Very helpful ! Thanks 🙂