-3

Why "without sharing " is used in an Apex class explicitly as we know that in absence of ' Without sharing' keyword, it is by default in apex class?

ramatbis
  • 41
  • 2
  • 10

2 Answers2

1

You'll want to read this question, but in short, a class with no declaration behaves in whatever mode was set from the calling class or context. When using "without sharing", the mode is always changed to ignore sharing rules for DML and queries.

sfdcfox
  • 489,769
  • 21
  • 458
  • 806
-1

Ensures that the sharing rules of the current user are not enforced. 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. 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.

public without sharing class noSharing {

// Code here

}

I think it helps.

  • Yes, Thanks for the response. But if we don't use 'without Sharing' Keyword also, it is by default 'Without sharing" in apex class. But why we explicitly use ' Without Sharing' keyword? – ramatbis Aug 16 '20 at 14:09