Recalculating Apex Managed Sharing

I am studying “Apex Managed Sharing” but I have a problem with “Recalculating Apex Managed Sharing”.

The Apex Developer Guide says:

Every time a custom object’s organization-wide sharing default access
level is updated, any Apex recalculation classes defined for
associated custom object are also executed.

I have created an Apex Class implementing Database.Batch interface and I have assigned this class for my Custom Object.

If I start the Recalculation from UI the code run correctly but if I change OWD the code is not executed.

Answer

To associate an Apex managed sharing recalculation class with a custom object:

  1. From the management settings for the custom object, go to Apex Sharing Recalculations.
  2. Choose the Apex class that recalculates the Apex sharing for this object. The class you choose must implement the Database.Batchable interface. You cannot associate the same Apex class multiple times with the same custom object.
  3. Click Save.

To run an Apex sharing recalculation, from the management settings for a custom object, go to Apex Sharing Recalculation, and then click New.

When working with Apex sharing recalculations, note the following.

  1. The Apex code that extends the sharing recalculation can process a maximum of five million records. If thisApex code affects more than five million records, the job fails immediately.
  2. You can monitor the status of Apex sharing recalculations in the Apex job queue.
  3. You can associate a maximum of five Apex sharing recalculations per custom object.
  4. You cannot associate Apex sharing recalculations with standard objects.

Attribution
Source : Link , Question Author : vt89 , Answer Author : David Reed

Leave a Comment