function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BhavanaBhavana 

sharing rule to share account record based on user field

Hi,

We have a few custom fields say A, B and C, all these are a lookup to User fields. The goal is to share the Account record with any User populated in the custom fields A, B or C. 
How can we create a sharing rule for this? Can we have public group with user names ? 
Please suggest me on this.

Thanks.
Vincent AlbiserVincent Albiser
Hi,

You can't use sharing rules to give access to values in lookup fields.
You should do an Apex Managed Sharing : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm

The Apex Managed Sharing Example is exactly your use case.

Regards,
BhavanaBhavana
Thanks @Vincent Albiser for the response.
Can we have a public group with the list of users and create a sharing rule to it?
Vincent AlbiserVincent Albiser
You can share with a public group but a sharing rule can only be based either on record owner or on field values, that doesn't look like your requirement.