So I've been reading about Apex Managed Sharing. I understand that this is implemented by creating a batch class, and then associating that class with a custom object. I have two questions.

  1. When exactly is this class run? Will the class run whenever a new record is inserted?
  2. If the answer to question 1 is 'yes', do I need to put any filter in the query locator so that only records newly inserted are processed, or is this done automatically?

Thx, Hamayoun


My understanding of this is that the apex managed sharing classes associated with a custom object are only run when the org wide sharing setting is toggled, i.e. from Public to Private.

The rest of your logic for assigning shares needs to be built into custom pages/controllers/triggers to insert shares as appropriate. The main benefit of apex managed sharing classes in my experience is for the transition from Public-> Private and vice versa.


My understanding is that it is up to you the implementor to decide 'when' to run the class and for what records. This may be as a result of some change in state or complex business rules, like I say determined by you and your requirement.

So, the 'what' to would basically come as the results from your QueryLocator in the start() method of the Batch apex job and the sharing (i.e. to whom) would be performed in the execute() method.

  • Phil, if that's the case, then what purpose is there to attaching the class to a custom object? – hamayoun Jun 27 '13 at 20:45
  • I guess if the sharing logic is more complex than what the other sharing methods will allow you to achieve. – Phil Hawthorn Jun 27 '13 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.