PDI · Question #220
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?
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)
How the community answered
(34 responses)- A6% (2)
- B3% (1)
- C88% (30)
- D3% (1)
Why each option
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.
`@RemoteAction` is used for exposing Apex methods to Visualforce pages for JavaScript remoting, not for wiring to properties in Lightning Web Components.
`@AuraEnabled` without `(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.
The `@AuraEnabled(cacheable=true)` annotation exposes an Apex method to Lightning Web Components for data retrieval, allowing the LWC framework to cache the method's results on the client-side for performance optimization when the data is read-only and doesn't require modifications.
The syntax `@RemoteAction(|cacheable=true)` is incorrect; `cacheable=true` is an attribute of `@AuraEnabled`, and `@RemoteAction` is for Visualforce remoting, not LWCs.
Concept tested: Apex method annotations for Lightning Web Components (LWC) wiring
Source: 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.