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

  1. Permissions:
    Only users with the “Modify All Data” permission can create, update, or delete sharing records associated with Apex sharing reasons.
  2. Deleting a Reason:
    Deleting an Apex sharing reason will remove all sharing entries for the object that rely on that reason.
  3. Limits:
    You can create up to 10 Apex sharing reasons per custom object.
  4. Metadata API:
    Apex sharing reasons can also be created and managed programmatically using the Metadata API.

Steps to Create an Apex Sharing Reason

  1. Navigate to the management settings for the desired custom object.
  2. Locate the Apex Sharing Reasons related list and click New.
  3. 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.
  4. 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.
  5. 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.

Related Posts
Salesforce OEM AppExchange
Salesforce OEM AppExchange

Expanding its reach beyond CRM, Salesforce.com has launched a new service called AppExchange OEM Edition, aimed at non-CRM service providers. Read more

The Salesforce Story
The Salesforce Story

In Marc Benioff's own words How did salesforce.com grow from a start up in a rented apartment into the world's Read more

Salesforce Jigsaw
Salesforce Jigsaw

Salesforce.com, a prominent figure in cloud computing, has finalized a deal to acquire Jigsaw, a wiki-style business contact database, for Read more

Health Cloud Brings Healthcare Transformation
Health Cloud Brings Healthcare Transformation

Following swiftly after last week's successful launch of Financial Services Cloud, Salesforce has announced the second installment in its series Read more