Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

Is there a way to validate a Salesforce id, maybe using RegEx? They are normally 15 chars or 18 chars but do they follow a pattern that we can use to check that it's a valid id.

Thanks in advance!

1 Answer

+1 vote
by (32.1k points)
edited by

You can validate an ID’s length, be it 15 or 18 by using this method. This method will validate possible characters existing with an ID using regular expressions.

Are you interested in learning Salesforce from scratch! Have a look at this interesting video on Salesforce provided by Intellipaat:

 static public String validateId(String Idparam) {

        String id = String.escapeSingleQuotes(Idparam);

        if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id)) 

     

    return id;

    }

    return null;

}

Go for this in-depth job-oriented salesforce training online now!

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...