Activity Forums Salesforce® Discussions What is the difference between with sharing and without sharing in Apex Code?

  • What is the difference between with sharing and without sharing in Apex Code?

    Posted by Suraj on April 21, 2017 at 1:18 pm

    What is the difference between with sharing and without sharing in Apex Code?

    Manpreet replied 7 years, 8 months ago 2 Members · 1 Reply
  • 1 Reply
  • Manpreet

    Member
    April 21, 2017 at 1:26 pm

    Hi suraj,

    I hope it will be helpful for you,

    Use the with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user. For example:

    public with sharing class sharingClass
    {
    // Code here
    }

    Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. For example:

    public without sharing class noSharing
    {
    // Code here
    }
    If a class is not declared as either with or without sharing, the current sharing rules remain in effect. This means that if the class is called by a class that has sharing enforced, then sharing is enforced for the called class.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos