1

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

2

(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:

  1. real groups (known as "Public Groups")
  2. system generated groups such as
    • queues
    • Roles
    • Territory-based groups
  3. and they all come in basic or "... and Subordinates" flavors
  4. 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").

  • You hit the nail on the head here. Doing some more digging, this group's Type was SharingRuleGroup. Doing an additional query to determine that, and then querying for GroupMembers should be sufficient for what I'm doing, but it does make me wonder how far nested these "groups" could get... – Michael Welburn Nov 20 '12 at 21:08
  • @MichaelWelburn - what stops you from abusing this SharingRuleGroup's Id right away? I never tried it but I'd imagine it to work without problems. Do you have to apply this special sharing really on each member separately? (you might want to check if the group is wiped out and reinserted with new Id when you click "recalculate" before following this route though!) – eyescream Nov 21 '12 at 0:07
  • If I try to create a Share with the SharingRuleGroup's ID, I receive an error that I am providing an invalid field value. – Michael Welburn Nov 21 '12 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.