Salesforce Platform Developer I (legacy) — Question 218
A developer is creating a Lightning web component to show a list of sales records.
The Sales Representative user should be able to see the commission field on each record. The Sales Assistant user should be able to see all fields on the record except the commission field.
How should this be enforced so that the component works for both users without showing any errors?
Answer options
- A. Use Lightning Data Service to get the collection of sales records.
- B. use WITH SECURITY_ENFORCED in the SOQL that fetches the data for the component.
- C. Use Lightning Locker Service to enforce sharing rules and field-level security.
- D. Use Security.stripInaccessible to remove fields inaccessible to the current user.
Correct answer: D
Explanation
The correct answer is D because Security.stripInaccessible effectively removes fields that the current user does not have access to, ensuring that the component displays only the appropriate fields based on user permissions. Options A and B do not provide the necessary filtering of fields based on user roles, while option C does not specifically address the requirement to remove inaccessible fields.