[SalesForce] How to find all users with whom the custom object is shared

I have a custom Salesforce Object whose records can be shared via a combination of sharing rules and manual sharing. I would like to create a List of User sObjects with access to the record.

The simplest way looks like it would be to select the UserOrGroupId from the MyObject__Sharing table, and then iterate through the UserOrGroupIds. If the entry is a User, add them to the list. If it is a Group, query the Group and add its users to the list.

However, this could add up to a lot of SOQL queries if the code is having to query many Groups for their members.

Is there any way that I could achieve this aim without an additional query per Group?

Thanks!

Best Answer

I dont think there is a current way around this, as the UserRecordAccess object only returns records for which a given user has access, not userid's for the given recordid.

If the purpose is just to show a user who all has access to a record, you can do this through the native interface by passing the current record id into a url like the one below which will take you to a sharing list showing you every user with access to that record (works for any record in any object)

salesforce.com/p/share/SharingBlowoutPage/d?parentId=RecordID