0 votes
1 view
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 (31.6k 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;


Welcome to Intellipaat Community. Get your technical queries answered by top developers !