You need to sign in to do that
Don't have an account?
inbox 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!
Thank you!
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
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
All Answers
Hi
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 :-
https://www.jitendrazaa.com/blog/salesforce/apex-based-sharing-in-salesforce/
If this help, please mark it as best answer.
Regards,
Priya Ranjan
Can we not achieve the same thing declaratively?
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
Consider a situation where you have a custom object called "Confidential Document" in your Salesforce org. The object contains sensitive information that should only be accessible to specific users based on their roles and a dynamic set of criteria. The access criteria could be based on a combination of record attributes, user attributes, or even data from external systems.
In this case, utilizing apex sharing would be beneficial because:
1. Dynamic Sharing Logic: Apex sharing allows you to implement custom logic to calculate record-level access dynamically. You can incorporate complex business rules, external data lookups, or even integration with external systems to determine who should have access to a particular record. This level of flexibility and customization is not available with declarative sharing settings.
2. Fine-grained Control: Apex sharing enables you to have fine-grained control over record access. You can define sharing rules at a granular level based on various factors, such as record attributes, user attributes, or even custom logic. This level of control may be necessary when the access requirements are more complex and cannot be adequately addressed by declarative sharing settings alone.
3. External Data Considerations: If the access to the "Confidential Document" records depends on data from external systems or APIs, using apex sharing would allow you to retrieve and process that data dynamically. You can incorporate external data sources into your sharing calculations and update sharing settings accordingly, ensuring accurate and up-to-date access control.
4. Integration with Existing Processes: Apex sharing can be seamlessly integrated with existing Apex code or business processes. If you already have custom logic written in Apex that determines record access for other objects, using apex sharing for the "Confidential Document" object ensures consistency and avoids duplicating the access control logic.
It's important to note that apex sharing should be used judiciously and only when necessary, as it introduces custom code complexity and requires proper testing and maintenance. It's recommended to thoroughly assess your requirements and evaluate the trade-offs before opting for apex sharing over declarative methods.