1

I have a question about Apex Managed Sharing best practices. We have a use case where we would need to create thousands of Apex Sharing records for each user.

I was wondering would it be better to put all the users into public group and create a single sharing record rather than multiple sharing records or there is no difference?

4

It's better to create a public group and share to it any time you need to do large scale sharing to the same sets of users.

See Salesforce Group Membership Sharing for Peak Performance:

When operations performed in Salesforce cause multiple users to lose or gain visibility to one or more records, the Salesforce group architecture can significantly reduce the maintenance and performance impact of those operations. It does this by adding or removing a single share for the group containing all of the members of that group.

Note that there's a caveat: if you change membership in your groups constantly, this approach can be contraindicated and there's other complications with group table locks.

| improve this answer | |
0

You would definitely want to do it leveraging groups as @DavidReed has pointed out. If there's any way you can add more granularity by breaking things into smaller groups first where there might be movement of users, that would likely be advantageous.

More than anything, because the entire sharing table gets recalculated when you have large numbers of records involved, it would still be wise to do this asynchronously. Remember that there will be a cascade effect as any kind of object sharing or group sharing record change trickles down between different group level records. With the volume of records you're talking about, using groups will be far more efficient than sharing records on an individual user basis.

| improve this answer | |

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.