I am studying “Apex Managed Sharing” but I have a problem with “Recalculating Apex Managed Sharing”.
Apex Developer Guidesays:
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.Batchinterface 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.
To associate an Apex managed sharing recalculation class with a custom object:
- From the management settings for the custom object, go to Apex Sharing Recalculations.
- 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.
- 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.
- 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.
- You can monitor the status of Apex sharing recalculations in the Apex job queue.
- You can associate a maximum of five Apex sharing recalculations per custom object.
- You cannot associate Apex sharing recalculations with standard objects.