SOQL query does not return results if it filters on UserOrgroupId
Last updated 2020-03-04 ·Reference W-6849033 ·Reported By 2 users
SOQL query does not return results if it filters on UserOrgroupId and the used ID is a role group on a criteria-based sharing rule (CBSR) for Opportunity (or another object whose parent is Account) if another CBSR targeting the same role group exists on Account.
1) Change Organization Wide Defaults for Account and Opportunity to Private.
2) Create a user role UR1.
3) Create a standard user U1 with role UR1.
4) Create a CBSR on Account based on a condition matching an existing account record not owned by U1. You can use "Name contains value" type of criteria. Share the records to Role and Subordinates of UR1.
5) Create a CBSR on Opportunity based on a condition matching an existing opportunity record not owned by U1. You can use "Name contains value" type of criteria. Share the records to Role and Subordinates of UR1 (notice that both rules must target the same group).
6) Navigate to Roles hierarchy in Setup and open UR1 page.
7) Find "Role and Subordinates" link next to "Sharing Groups" label. Click on the link and get the group id (00D...) from the URL. This will be id to use in the SOQL queries below.
8) Run below SOQL query:
SELECT Id, OpportunityId FROM OpportunityShare WHERE UserOrGroupId = UR1
Actual result: No results are returned.
Expected result: OpportunityShare records are returned for each opportunity matched by the CBSR on Opportunty created before.
If you need to find how many OpportunityShare exists for a given opportunity, consider using Apex to get all OpportunityShare for that opportunity (filter on OpportunityId), and fetch the required OpportunityShare via a for loop that checks the UserOrGroupId to find a match.
Alternatively, you could consider creating a public group that includes just one member (e.g. role group UR1 as above), and then modify the CBSR on Opportunity so that it targets this public group rather than UR1.
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.