Created
July 29, 2016 02:04
Star
You must be signed in to star a gist
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