Question 11
Choose 3
Refer to the following code snippet:

A developer created a JavaScript function as part of a Lightning web component (LWC) that surfaces information about Leads by wire calling geyFetchLeadList whencertain criteria are met.
Which three changes should the developer implement in the Apex class above to ensure the LWC can display data efficiently while preserving security?
(Choose 3 answers)

A developer created a JavaScript function as part of a Lightning web component (LWC) that surfaces information about Leads by wire calling geyFetchLeadList whencertain criteria are met.
Which three changes should the developer implement in the Apex class above to ensure the LWC can display data efficiently while preserving security?
(Choose 3 answers)
Correct answer:
A. Annotate the Apex method with @AuraEnabled.
B. Implement the with sharing keyword in the class declaration.
E. Annotate the Apex method with @AuraEnabled(Cacheable=True).
Explanation:
✅ A. Annotate the Apex method with @AuraEnabled
→ Why: Lightning Web Components need Apex methods exposed to be callable.
→ The @AuraEnabled annotation makes the method accessible from the frontend.
→ For @wire usage in LWC, this annotation is required.
@AuraEnabled
public static List getFetchLeadList(...) { ... }
✅ B. Implement the with sharing keyword in the class declaration
→ Why: This enforces organization-wide default sharing rules, ensuring that users only see data they have access to.
→ Without with sharing, the class runs in system mode, which could expose sensitive data the user shouldn’t see.
public with sharing class LeadController { ... }
✅ E. Annotate the Apex method with @AuraEnabled(cacheable=true)
→ Why: Makes the method compatible with @wire in LWC and improves performance by caching results.
→ Required for read-only, idempotent operations like querying data (as in this case).
→ Reduces server load and speeds up LWC rendering.
@AuraEnabled(cacheable=true)
public static List getFetchLeadList(...) { ... }
❌ C. Implement the with keyword in the class declaration
》 Why it's incorrect: There’s no with keyword on its own in Apex. It must be with sharing or without sharing. So this option is invalid syntax.
❌ D. Use the WITH SECURITY_ENFORCED clause within the SOQL query
Why it’s not required here:
》 WITH SECURITY_ENFORCED is only supported on certain object types and only applies to field- and object-level access.
》 Since the class will use with sharing, and no restricted fields are being queried, this is not necessary here — though optionally good for enhanced security.
✅ A. Annotate the Apex method with @AuraEnabled
→ Why: Lightning Web Components need Apex methods exposed to be callable.
→ The @AuraEnabled annotation makes the method accessible from the frontend.
→ For @wire usage in LWC, this annotation is required.
@AuraEnabled
public static List
✅ B. Implement the with sharing keyword in the class declaration
→ Why: This enforces organization-wide default sharing rules, ensuring that users only see data they have access to.
→ Without with sharing, the class runs in system mode, which could expose sensitive data the user shouldn’t see.
public with sharing class LeadController { ... }
✅ E. Annotate the Apex method with @AuraEnabled(cacheable=true)
→ Why: Makes the method compatible with @wire in LWC and improves performance by caching results.
→ Required for read-only, idempotent operations like querying data (as in this case).
→ Reduces server load and speeds up LWC rendering.
@AuraEnabled(cacheable=true)
public static List
❌ C. Implement the with keyword in the class declaration
》 Why it's incorrect: There’s no with keyword on its own in Apex. It must be with sharing or without sharing. So this option is invalid syntax.
❌ D. Use the WITH SECURITY_ENFORCED clause within the SOQL query
Why it’s not required here:
》 WITH SECURITY_ENFORCED is only supported on certain object types and only applies to field- and object-level access.
》 Since the class will use with sharing, and no restricted fields are being queried, this is not necessary here — though optionally good for enhanced security.


