Salesforce Platform Developer I (legacy) — Question 44

Universal Containers implemented a private sharing model for the Account object. A custom Account search tool was developed with Apex to help sales representatives find accounts that match multiple criteria they specify. Since its release, users of the tool report they can see Accounts they do not own.
What should the developer use to enforce sharing permissions for the currently logged-in user while using the custom search tool?

Answer options

Correct answer: C

Explanation

The correct answer is C, as using the with sharing keyword in the class declaration ensures that the sharing rules for the logged-in user are honored, preventing access to accounts they do not own. Option A does not enforce sharing rules, it only checks access. Option B is a filtering method but does not enforce sharing on the class level. Option D explicitly ignores sharing rules, which is contrary to the requirement to respect user permissions.