Activity Forums Salesforce® Discussions Keyword “with sharing” runs in system mode then why keyword “without sharing” is introduced in Salesforce apex?

  • shariq

    Member
    September 22, 2018 at 10:22 pm

    Lets take example, there is classA declared using “with sharing” and it calls classB method. classB is not declared with any keyword then by default “with sharing” will be applied to that class because originating call is done through classA. To avoid this we have to explicitly define classB with keyword “without sharing”.

  • Parul

    Member
    September 23, 2018 at 4:06 am

    Without Sharing is reserved for cases where the User does not have access to the records, but there is a need to update them based on user input.

    Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. For example, you may want to explicitly turn off sharing rule enforcement when a class acquires sharing rules when it is called from another class that is declared using with sharing.
    public without sharing class noSharing {
    // Code here

    }

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos