Skip to content

Instantly share code, notes, and snippets.



Created Jul 29, 2016
What would you like to do?
Validating a record Id in Salesforce from a String
public class Utils {
static Boolean validId(String recordIdString) {
try {
Id recordId = (Id)recordIdString;
String sobjectName = String.valueOf(recordId.getSObjectType());
return Database.countQuery('SELECT COUNT() FROM '+sobjectName+' WHERE Id = :recordId') > 0;
} catch(Exception e) {
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment