Universal Containers は、アカウント オブジェクトのプライベート共有モデルを実装しました。営業担当者が指定した複数の条件に一致するアカウントを見つけられるように、Apex を使用してカスタム アカウント検索ツールが開発されました。リリース以来、ツールのユーザーからは、自分が所有していないアカウントが表示されることがあるとの報告があります。
カスタム検索ツールを使用しているときに、現在ログインしているユーザーに共有権限を強制するには、開発者は何を使用する必要がありますか?
正解:B
Since users can see Accounts they do not own in a private sharing model, the custom Apex code is likely not enforcing sharing rules. To enforce sharing permissions, the developer should use the with sharing keyword on the class declaration.
with sharing Keyword: This enforces the sharing rules of the current user, ensuring that the Apex class respects the user's record-level access permissions.
"Use the with sharing keyword when declaring a class to enforce the sharing rules that apply to the current user."
- Apex Developer Guide: Using the with sharing or without sharing Keywords Private Sharing Model: In a private sharing model, users should only see records they own or have been shared with them.
"Private: Only the record owner and users above that role in the hierarchy can view, edit, and report on those records."
- Salesforce Help: Organization-Wide Sharing Defaults
Why Not Other Options:
A . Use the schema describe calls to determine if the logged-in user has access to the Account object: Schema describe calls check for object-level access, not record-level sharing.
"Schema describe information provides metadata about object and field properties, but it doesn't enforce record-level access."
- Apex Developer Guide: Schema Namespace
C . Use the without sharing keyword on the class declaration: This runs the class in system context, ignoring sharing rules, which is the opposite of what's needed.
"Classes declared as without sharing or those that do not specify a keyword default to without sharing and don't enforce the sharing rules of the current user."
- Apex Developer Guide: Using the with sharing or without sharing Keywords D . Use the UserInfo Apex class to filter all SOQL queries to return records owned by the logged-in user: Manually filtering queries is error-prone and not a best practice when with sharing can enforce sharing automatically.
"Avoid hardcoding user or profile IDs and using the UserInfo class to enforce security. Instead, use declarative security features."
- Apex Developer Guide: Enforcing Security in Apex
Conclusion: By declaring the class with with sharing, the Apex code respects the user's sharing rules, ensuring that users only see Accounts they have access to.