+ Start a Discussion
GaneeeshGaneeesh 

Difference between Apex sharing and and sharing rules

Hi  All, I would like to know what is the Difference between Apex sharing and and sharing rules. If anybody know the difference please share to me.
Sfdc CloudSfdc Cloud
Hi ,
Apex code runs in system context. In system context, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren’t applied for the current user.
Use the with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user.
Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced.
Refer below link
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm

If this answer help,Please mark it as best answer to help others :)
GaneeeshGaneeesh
Hi thanx for your reply


Here I am not akhing difference between with sharing and without sharin.

Here i need difference between Apex based(Customization) sharing and normarl sharing rules(through configuration). 
pradeep naredlapradeep naredla
Hi ganeesh,
          First you have to notice one thing that with sharing of apex is not at all related to the sharing rule.

1) Sharing rule is used to just extend the access defined in OWD criteria for an user for a particular object's records.

2) and the apex sharing rule dealing with enforcing  the sharing rules that apply to the current user. That means when a user is using the class the sharing rules are aplicable to the user (or) not.

thanks.
raj_sfdccraj_sfdcc
Hi Ganeesh,

There can be a situation where you can not share records to targeted users by using Sharing rules . In these situation you can share the access by using programatic way .

Please go through below post where you can find simple use cases explained with helpful descriptions .

Apex Managed Sharing With Real Time Example In SaelsForce (https://salessforcehacks.blogspot.com/2020/01/apex-managed-sharing-with-real-time.html)