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

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

If this answer help,Please mark it as best answer to help others :)
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.

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 (