• #15787
    Salesforce | Mohit Mohit #401
    Forcetalks

    How can we generate the random string in Salesforce?

    Hi All,

    How can we generate the random string in salesforce?

    I am in scenario in which I want to generate random string sequence in apex .

    Please give suggestion

     

    #15794
    Salesforce | PRANAV PRANAV #679
    Forcetalks

    Hi Mohit,

    Try this code

    public class generateRandomString {
    public static String generateRandomString(Integer len) {
    final String chars = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz’;
    String randStr = ”;
    while (randStr.length() < len) {
    Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
    randStr += chars.substring(idx, idx+1);
    }
    return randStr;
    }
    }

    Hope this helps you.

    Thanks

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?