Creating Apex Sharing Reasons
Apex sharing reasons are essential for implementing Apex-managed sharing on custom objects. They define the purpose behind the sharing of records and streamline the process of managing sharing entries programmatically. By using Apex sharing reasons, you can:
Thank you for reading this post, don't forget to subscribe!- Clearly identify why sharing was implemented for a record.
- Simplify code for updating or deleting sharing entries.
- Enable sharing of a record with the same user or group for different purposes by using multiple reasons.
Why Use Apex Sharing Reasons?
When Apex sharing reasons are configured, they appear in the Reason column of the sharing settings for a custom object record. This visibility helps users and administrators understand the intent behind each sharing entry.
Key Considerations
- Permissions:
Only users with the “Modify All Data” permission can create, update, or delete sharing records associated with Apex sharing reasons. - Deleting a Reason:
Deleting an Apex sharing reason will remove all sharing entries for the object that rely on that reason. - Limits:
You can create up to 10 Apex sharing reasons per custom object. - Metadata API:
Apex sharing reasons can also be created and managed programmatically using the Metadata API.
Steps to Create an Apex Sharing Reason
- Navigate to the management settings for the desired custom object.
- Locate the Apex Sharing Reasons related list and click New.
- Enter a Label:
- This label will display in the Reason column in the sharing settings of the record.
- Labels can be translated using the Translation Workbench.
- Enter a Name:
- The name is used in API and Apex references.
- It must:
- Start with a letter.
- Be unique within your organization.
- Contain only alphanumeric characters and underscores.
- Avoid spaces, consecutive underscores, or ending with an underscore.
- Click Save.
Additional Information
For more details about Apex-managed sharing, consult the Apex Developer Guide. This resource provides comprehensive insights into managing record sharing programmatically in Salesforce.
By implementing Apex sharing reasons thoughtfully, you can enhance both the functionality and clarity of your record-sharing processes.