With the field in place, we can set up the rule which will define the sharing.
From the app launcher, open the FormulaShare app (if you don't see this, check that the permission set is assigned).
Rules are created from the FormulaShare Rules tab. Click "New Rule" to start setting one up.
The options below are set in this screen:
- Label, API Name and Description: Add something to distinguish this rule from others
- Object to Share: Select the object from the list of those available to share. Objects included are those which:
- Support sharing - child objects in a master-detail relationship and some standard objects do not support independent sharing rules
- Have an internal or external organisation-wide default sharing setting of either Private (for Read or Edit access levels) or Public Read Only (for Edit access level)
- Location of field with user, role or group: Objects can be shared based on values in fields on either the object itself, or an object related by a lookup or master-detail field. If the second of these options is used, records will be shared with all users, roles or groups specified in the field selected on all related records. For more details on sharing application, see rule types and sharing logic
- Share With: The type of entity this rule should share with. Options are "Users", "Roles", "Roles and Internal Subordinates", "Roles, Internal and Portal Subordinates" (includes both community and portal users) and "Public Groups"
- Specified in Field: The field which contains a reference to the user, role or group needing access. Fields which can be chosen are text fields, formula fields returning text and or lookups to the user object. The field selected should be populated with either the Salesforce 15 or 18 character id of the user role or group, or the role or group name (developer name) for sharing to work correctly
- Containing Type: Choose either "Id" or "Name" depending on which of these are populated in the field selected
- Access Level: Set to Read or Edit. For objects with an organisation-wide default sharing setting of Public Read Only, only the Edit option will be available
- Sharing Reason: Will be available for custom objects only. A unique sharing reason must be used for each rule on the same object. To set up a new reason, click the Manage Apex Sharing Reasons link below the field - clicking the refresh icon after setting this will show the reason to be selected
Clicking Save on this screen deploys details of the rule to be set up as custom metadata in the FormulaShare Rules custom metadata type. See the accessing and deploying rule metadata section for details of this.