Hi,
Here we are going to learn how to remove inaccessible fields from the query:
Let's take a scenario
A display table for campaign data must always show the BudgetedCost. The ActualCost must be shown only to users who have permission to read that field.
Code Snippet:
SObjectAccessDecision securityDecision =
Security.stripInaccessible(AccessType.READABLE,
[SELECT Name, BudgetedCost, ActualCost FROM Campaign];
);
// Construct the output table
if (securityDecision.getRemovedFields().get('Campaign').contains('ActualCost')) {
for (Campaign c : securityDecision.getRecords()) {
//System.debug Output: Name, BudgetedCost
}
} else {
for (Campaign c : securityDecision.getRecords()) {
//System.debug Output: Name, BudgetedCost, ActualCost
}
}
Reference:
No comments:
Post a Comment