Skip to content

Instantly share code, notes, and snippets.

@brianmfear
Created July 29, 2016 02:04
Show Gist options
  • Save brianmfear/6ccca2e48e34938132cc4263217b8b22 to your computer and use it in GitHub Desktop.
Save brianmfear/6ccca2e48e34938132cc4263217b8b22 to your computer and use it in GitHub Desktop.
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