+ Start a Discussion
inbox outbox 7inbox outbox 7 

Could anyone tell me the reason why we use apex sharing?

I am looking for a scenario as to, when we use apex sharing over declarative ways. 
Thank you!
PriyaPriya (Salesforce Developers) 


Consider this scenario :- 

On Opportunity, you want to give access to record to some users which are in related list.
One way is to manually share the record which will need the interference of opportunity owner. But everyone will love automated solution.
Apex managed sharing provides developers with the ability to support an application’s particular sharing requirements programmatically via Apex code.

For more detail :- 

If this help, please mark it as best answer.


Priya Ranjan

inbox outbox 7inbox outbox 7
Can we not achieve the same thing declaratively?
dhwjidh dskoidiodhwjidh dskoidio
We use this apex sharing just because its more responsive like you see here (https://myuniversalremotecodes.com/) and the other choices are not as competent as you see it.
Tushar KhorateTushar Khorate
Apex managed sharing must use an Apex sharing reason . Apex sharing reasons are a way for developers to track why they shared a record with a user or group of users. Using multiple Apex sharing reasons simplifies the coding required to make updates and deletions of sharing records.
Manual Sharing
Manual Sharing is used to share the record Manually. For Example, you are working on an Opportunity record and You need help from your colleague. In this case, you can share the record with him/her and take the help.
Manual Sharing is not available for Lightning Experience
Click here for Manual Sharing for Salesforce Lightning.
Apex Managed Sharing
Apex Managed Sharing only works when the OWD is either private or Public Read Only.
Apex Managed Sharing is used to share the records when you can not use Sharing rules.
We do insert the Share Record using Apex trigger/class.
Maintained across ownership changes
Requires “Modify All” permission

For more detail information see this: https://www.youtube.com/watch?v=9ZnMNPBJ5D0&ab_channel=SFDCPanther%2B (https://www.youtube.com/watch?v=9ZnMNPBJ5D0&ab_channel=SFDCPanther%2B)
If you found this helpful then mark it as best answer so other can also see this if they want help.

Thank you
Jeanette MyersJeanette Myers
Can someone hlep me to get the code? I am looking for a code of this page I want to make same design for my blog post https://apkmud.com/episode-mod-apk/