102k views
4 votes
What is the recommended approach for recalculating Apex managed sharing on a record?

1 Answer

7 votes

Final answer:

To recalculate Apex managed sharing on a record in Salesforce, first delete all associated sharing records and then enforce the sharing rules or custom logic through Apex code. This process is critical after modifying sharing settings or when record ownership changes.

Step-by-step explanation:

The recommended approach for recalculating Apex managed sharing on a record in Salesforce involves using the Apex sharing recalculation framework. This process involves removing all the sharing records associated with the record that needs sharing recalculation and then executing a code snippet that enforces sharing rules or triggers any predefined sharing logic.

Here is a general outline of steps to recalculate managed sharing:

  1. Identify the records whose sharing needs to be recalculated.
  2. Delete existing sharing rules using the 'delete' DML operation on the Share objects.
  3. Invoke the Share record generation logic, which may be managed through custom Apex classes or triggers.
  4. Test the recalculated sharing rules to ensure they meet the defined data access requirements.

Recalculation of Apex managed sharing is particularly important after making changes to sharing rules or access levels or when records are transferred between users.

User Jared Eitnier
by
8.2k points