I am writing a trigger that looks up to a parent (Lookup) Opportunity from a custom object, and am coming across an interesting problem. I have a sharing rule set up on the Opportunity to grant Edit access to a group based on a checkbox being set. However, when I query for the OpportunityShares against that Opportunity, the UserOrGroupId for that rule is an ID that does not match. I can't tell if there is some sort of wrapper around my group regarding the sharing rule, and due to that I can't complete my corresponding trigger that dynamically propagates the Opportunity security to my custom object (which can't be a Master-Detail for other reasons).
For comparison sake:
Group ID: 00GD0000001Afjh
UserOrGroupID from query: 00GD0000001AfLxMAK
Attribution to: Michael Welburn
Possible Suggestion/Solution #1
(community wiki)
Groups can consist of Users or other Groups (hence the UserOrGroupId
present both in OpportunityShare
and in GroupMember
). In the Group*
tables you can find definitions of:
- real groups (known as "Public Groups")
- system generated groups such as
- queues
- Roles
- Territory-based groups
- and they all come in basic or "... and Subordinates" flavors
- and if you have Customer Portal there's even more fun ;)
In the Group
table the Type
field is a very good hint as well as RelatedToId
(you could check the ID prefix to determine whether it points to Role or Territory for example).
Similar with GroupMember.UserOrGroupId
but this damn thing doesn't handle relational queries well.
In the past I had to do some recursive checks in the structure, hand-craft Maps of userIds, Group Ids etc to figure out where to apply the sharing. Luckily I never had to dig more than 2-3 levels deep.
This is also an interesting read: http://help.salesforce.com/apex/HTViewSolution?id=000170718
With Winter'13 and polymorphic SOQL it might be better but you have to contact Support to opt-in. And even then I can't imagine it can help much (I miss subqueries in GroupMember and ability to use "dot" up to 5 times more than dynamic "which fields to retrieve").
Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4621