Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
SObjectAccessDecision Class
Namespace
SObjectAccessDecision Methods
The following are methods for SObjectAccessDecision.
getModifiedIndexes()
Signature
public Set<Integer> getModifiedIndexes()
Return Value
Type: Set<Integer>
A set of unsigned integers that represent the row indexes of the modified sObjects.
Example
In this example, the user doesn’t have permission to update the AnnualRevenue field of an Account.
1List<Account> accounts = new List<Account>{
2 new Account(Name='Account1', AnnualRevenue=1000),
3 new Account(Name='Account2')
4};
5
6// Strip fields that are not updatable
7SObjectAccessDecision decision = Security.stripInaccessible(
8 AccessType.UPDATABLE,
9 accounts);
10
11// Print stripped records
12for (SObject strippedAccount : decision.getRecords()) {
13 System.debug(strippedAccount);
14}
15
16// Print modified indexes
17System.debug(decision.getModifiedIndexes());getRecords()
Usage
The stripInaccessible method performs field-level access check for the source records in the context of the current user’s operation. The getRecords() method returns the new records that contain only the fields that the current user has access to.
Signature
public List<SObject> getRecords()
Return Value
Type: List<SObject>
Even if the result list contains only one sObject, the return type is still a list (of size one).
Example
In this example, the user doesn’t have permission to update the AnnualRevenue field of an Account.
1List<Account> accounts = new List<Account>{
2 new Account(Name='Account1', AnnualRevenue=1000),
3 new Account(Name='Account2')
4};
5
6// Strip fields that are not updatable
7SObjectAccessDecision decision = Security.stripInaccessible(
8 AccessType.UPDATABLE,
9 accounts);
10
11// Print stripped records
12for (SObject strippedAccount : decision.getRecords()) {
13 System.debug(strippedAccount);
14}getRemovedFields()
Signature
public Map<String,Set<String>> getRemovedFields()
Return Value
Type: Map<String,Set<String>>
Example
In this example, the user doesn’t have permission to update the AnnualRevenue field of an Account.
1List<Account> accounts = new List<Account>{
2 new Account(Name='Account1', AnnualRevenue=1000),
3 new Account(Name='Account2')
4};
5
6// Strip fields that are not updatable
7SObjectAccessDecision decision = Security.stripInaccessible(
8 AccessType.UPDATABLE,
9 accounts);
10
11// Print stripped records
12for (SObject strippedAccount : decision.getRecords()) {
13 System.debug(strippedAccount);
14}
15// Print removed fields
16System.debug(decision.getRemovedFields());