I'm trying to determine (in APEX) what the security level is of a custom sObject (for a UI)
For example:
mysObject__c (Public Read Only, Private, etc.)
I know it's possible to test the by inserting a __share and trapping the exception that is returned, but I'm concerned about other unknowns there are.
Should I test with any random instance of the sObject as a ParentId, and should I Just use the current user as the UserOrGroupId
mysObject__c m = [SELECT id FROM mysObject__c];
mysObject__share testShare = new mysObject__share();
testShare.ParentId = m.Id; // using first record returned
testShare.UserOrGroupId = UserInfo.getUserId(); // using current user id
testShare.AccessLevel = 'Read';
Database.SaveResult sr = Database.insert(testShare);
if(!sr.isSuccess()){
// look for the exception
Database.Error err = sr.getErrors()[0];
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION && err.getMessage().contains('AccessLevel')){
{
system.debug('object is public read');
}
}
Does this guarantee the result for every object of that type? And which 'OwnerId' - will always be same exception be thrown even if the user is the owner of the record in question?
Is there a call to explicitly get the security level.