Created
July 29, 2016 02:04
-
-
Save brianmfear/6ccca2e48e34938132cc4263217b8b22 to your computer and use it in GitHub Desktop.
Validating a record Id in Salesforce from a String
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
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