Skip to content

Instantly share code, notes, and snippets.

@hasanthaera
Created April 23, 2015 06:33
Show Gist options
  • Save hasanthaera/506b80f562fea439c46e to your computer and use it in GitHub Desktop.
Save hasanthaera/506b80f562fea439c46e to your computer and use it in GitHub Desktop.
Validating Record ID : Salesforce
/**
* isValidId
*
* This will check weather the value provided as the ID is exactly
* mathes its format with using regex
*
**/
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;
}
/**
* isValidId
*
* This will check weather the value provided as the ID is exactly
* mathes its format.
*
**/
public static boolean isValidId(String Idparam) {
if(String.isBlank(Idparam)){ return false; }
Id validId;
try {
validId = Idparam;
return true;
} catch (Exception ex) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment