function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
B_BajajB_Bajaj 

Apex Manged Sharing for detail object

Hi Everyone,

I am looking for a solution where I need to implement Apex Manged Sharing for a detail custom object whose master object is a standard object in my case it is account.

I have an object say Meetings which has master detail field which is set up with Account. I have done the apex managed sharing for a custom object but i am not sure how to proceed with this case. Few things I am curios about are
  • When there is no apex sharing reason for standard objects how to proceed.
  • There is no detail__Sharing (meeting__share in my case) then how to develop.
It will be helpful if you can provide a pusedo code for the same or a way to solve this.

Thanks in anticipation.

Thanks
Bhisham Bajaj
bob_buzzardbob_buzzard
You can't do this I'm afraid - from the docs:

--- snip ---

Custom objects on the detail side of a master-detail relationship cannot have sharing rules, manual sharing, or queues, as these require the Owner field.

--- snip ---
B_BajajB_Bajaj
Thanks Bob so should I find a way to apply Apex managed Sharing for Account which will be adopted by all of its detail objects automatically but I fear that standard objects don't allow Apex sharing reason which I used in Apex managed sharing for a custom object. If not then what other options I have.

Any help is appreciated.

bob_buzzardbob_buzzard
You are correct that you can't use a custom Apex sharing reason for a standard object. Is it possible to convert your master-detail relationship to a lookup?
B_BajajB_Bajaj
Oopss.... well this was the last option I was considering converting M-D into Look up and develop triggers for the rollup fields but I think that is the only option I have.

Thanks for your help.
bob_buzzardbob_buzzard
I always use Anthony Victorio's trigger utility - saved me a ton of time adding rollup functionality via lookup:

http://www.anthonyvictorio.com/salesforce/roll-up-summary-trigger/

You can hit governor limits if you have a lots of rollups (usually around 20+), aside from that I've had no problems.