Skip to main content

Sharing

with sharing is a default option option, because of USER_MODE.

You can control sharing rules only in .systemMode().

public inherited sharing class AccountSelector {

public static SOQL Query {
get {
return SOQL.of(Account.sObjectType)
.with(new List<sObjectField>{
Account.Id,
Account.Name
});
}
}
}

public with sharing class MyController {

public static List<Account> getAccountsWithSharing() {
return AccountSelector.Query
.systemMode()
.withSharing()
.asList();
}

public static List<Account> getAccountsWithoutSharing() {
return AccountSelector.Query
.systemMode()
.withoutSharing()
.asList();
}
}