Another Salesforce blog!!!

Salesforce, Apex

Validating an Id length(15 or 18)


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;
}

Leave a Reply

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

*