Salesforce Platform Developer I (legacy) — Question 254

While developing an Apex class with custom search functionality that will be launched from a Lightning Web Component, how can the developer ensure only records accessible to the currently logged in user are displayed?

Answer options

Correct answer: A

Explanation

The correct answer is A, as using the WITH SECURITY_ENFORCED clause in the SOQL ensures that the query respects the user's field-level and object-level permissions. Option B, inherited sharing, does not apply to this context because it relates to sharing rules in classes, not specific queries. Option C, with sharing, only enforces sharing rules, not field permissions, while option D, without sharing, ignores sharing rules entirely, making it unsuitable for this requirement.