Created
April 23, 2015 06:33
-
-
Save hasanthaera/506b80f562fea439c46e to your computer and use it in GitHub Desktop.
Validating Record ID : Salesforce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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