Valid PDI Dumps shared by ExamDiscuss.com for Helping Passing PDI Exam! ExamDiscuss.com now offer the newest PDI exam dumps, the ExamDiscuss.com PDI exam questions have been updated and answers have been corrected get the newest ExamDiscuss.com PDI dumps with Test Engine here:
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?
Correct Answer: A
* WhyWITH SECURITY_ENFORCED? * Ensures field-level security and sharing rules are enforced in SOQL queries. * Prevents unauthorized records or fields from being accessed or displayed. * Why Not Other Options? * B and C:with sharingandinherited sharingenforce record-level access but do not handle field-level security. * D:without sharingignores sharing rules, which would display all records regardless of user permissions. References:Security in SOQL:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_enforced.htm
Recent Comments (The most recent comments are at the top.)
Yassine - Oct 20, 2026
Answer: C. Use the with sharing keyword.
This is the same idea as the Account search question you just asked. Apex runs in system mode by default and ignores the user’s record access. Declaring the class with sharing makes its queries return only records the logged-in user can access through ownership, roles, sharing rules and teams.
apex public with sharing class RecordSearchController { @AuraEnabled(cacheable=true) public static List<Account> search(String term) { String key = '%' + term + '%'; return [SELECT Id, Name FROM Account WHERE Name LIKE :key]; } }
The other options:
A. WITH SECURITY_ENFORCED: It enforces object and field-level security, not record-level sharing. It throws an exception if the user can’t read a field in the query, and a query with it still returns records the user shouldn’t see if the class runs without sharing. It is a good addition, but it doesn’t answer “records accessible to the user”. B. inherited sharing: The class takes the sharing mode of whatever calls it. When it is the entry point from an LWC, it runs as with sharing by default, so it can work here. It depends on the caller, though, and it is not the explicit guarantee the question asks for. D. without sharing: It ignores sharing rules and exposes every record....
sam - Oct 01, 2026
I think answer is C as with sharing apply the record level security and With SECURITY_ENFORCED is for field level security
Long - Dec 10, 2025
the answer is C
alias - Dec 09, 2025
The answer could be C on this. Can anyone else verify?
Recent Comments (The most recent comments are at the top.)
Answer: C. Use the with sharing keyword.
This is the same idea as the Account search question you just asked. Apex runs in system mode by default and ignores the user’s record access. Declaring the class with sharing makes its queries return only records the logged-in user can access through ownership, roles, sharing rules and teams.
apex
public with sharing class RecordSearchController {
@AuraEnabled(cacheable=true)
public static List<Account> search(String term) {
String key = '%' + term + '%';
return [SELECT Id, Name FROM Account WHERE Name LIKE :key];
}
}
The other options:
A. WITH SECURITY_ENFORCED: It enforces object and field-level security, not record-level sharing. It throws an exception if the user can’t read a field in the query, and a query with it still returns records the user shouldn’t see if the class runs without sharing. It is a good addition, but it doesn’t answer “records accessible to the user”.
B. inherited sharing: The class takes the sharing mode of whatever calls it. When it is the entry point from an LWC, it runs as with sharing by default, so it can work here. It depends on the caller, though, and it is not the explicit guarantee the question asks for.
D. without sharing: It ignores sharing rules and exposes every record....
I think answer is C as with sharing apply the record level security and With SECURITY_ENFORCED is for field level security
the answer is C
The answer could be C on this. Can anyone else verify?