PDI · Question #220
PDI Question #220: Real Exam Question with Answer & Explanation
The correct answer is C: @AureEnabled (cacheable=true). To enable an Apex method for wiring in a Lightning Web Component, it must be annotated with @AuraEnabled and specifically (cacheable=true) if the data is read-only and can be cached client-side.
Question
Which annotation should a developer use on an Apex method to make it available to be wired to a property in a Lightning web component?
Options
- A@RemoteAction
- B@AureEnabled
- C@AureEnabled (cacheable=true)
- D@RemoteAction(|cacheable=true)
Explanation
To enable an Apex method for wiring in a Lightning Web Component, it must be annotated with @AuraEnabled and specifically (cacheable=true) if the data is read-only and can be cached client-side.
Common mistakes.
- A.
@RemoteActionis used for exposing Apex methods to Visualforce pages for JavaScript remoting, not for wiring to properties in Lightning Web Components. - B.
@AuraEnabledwithout(cacheable=true)exposes the method but does not enable client-side caching, which is a key performance feature for wired properties that retrieve read-only data. - D. The syntax
@RemoteAction(|cacheable=true)is incorrect;cacheable=trueis an attribute of@AuraEnabled, and@RemoteActionis for Visualforce remoting, not LWCs.
Concept tested. Apex method annotations for Lightning Web Components (LWC) wiring
Reference. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apex_api_methods.htm
Topics
Community Discussion
No community discussion yet for this question.