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?