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:

  • 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
Who is Salesforce?
Salesforce

Who is Salesforce? Here is their story in their own words. From our inception, we've proudly embraced the identity of Read more

Salesforce Marketing Cloud Transactional Emails
Salesforce Marketing Cloud

Salesforce Marketing Cloud Transactional Emails are immediate, automated, non-promotional messages crucial to business operations and customer satisfaction, such as order Read more

Salesforce Unites Einstein Analytics with Financial CRM
Financial Services Sector

Salesforce has unveiled a comprehensive analytics solution tailored for wealth managers, home office professionals, and retail bankers, merging its Financial Read more

AI-Driven Propensity Scores
AI-driven propensity scores

AI plays a crucial role in propensity score estimation as it can discern underlying patterns between treatments and confounding variables Read more