SHARING MODE
For more details check Check SOQL API - SHARING MODE and Advanced - SHARING MODE
NOTE! 🚨 All examples use inline queries built with the SOQL Lib Query Builder. If you are using a selector, replace
SOQL.of(...)
withYourSelectorName.query()
.
with sharing​
with sharing
is a default option option, because of USER_MODE
. You can control sharing rules only in .systemMode()
.
WITH USER_MODE​
No action needed. USER_MODE
enforces not only object and field-level security but also sharing rules (with sharing).
SOQL
SELECT Id
FROM Account
WITH USER_MODE
SOQL Lib
SOQL.of(Account.SObjectType)
.toList();
or explicity:
SOQL.of(Account.SObjectType)
.userMode()
.toList();
WITH SYSTEM_MODE​
SOQL
SELECT Id
FROM Account
WITH SYSTEM_MODE
SOQL Lib
SOQL.of(Account.SObjectType)
.systemMode()
.withSharing()
.toList();
without sharing​
You have to use on WITH SYSTEM_MODE
.systemMode()
to use withoutSharing()
.
SOQL
SELECT Id
FROM Account
WITH SYSTEM_MODE
SOQL Lib
SOQL.of(Account.SObjectType)
.systemMode()
.withoutSharing()
.toList();
inherited sharing​
inherited sharing
is a default sharing mode when is .systemMode()
enabled.
SOQL
SELECT Id
FROM Account
WITH SYSTEM_MODE
SOQL Lib
SOQL.of(Account.SObjectType)
.systemMode()
.toList();