Plat-Dev-201 practice question 9 of 30

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?

Full set: 204 questions
Answer options
A: @AuraEnabled(cacneable=true) Correct answer
B: @RemoteAction (cacheable-true)
C: @RemoteAction
D: @AuraEnabled
Correct Answer:
A. @AuraEnabled(cacneable=true)
Explanation

To make an Apex method available to a Lightning Web Component's @wire service, it must be annotated with @AuraEnabled(cacheable=true). The @AuraEnabled annotation exposes the method to Lightning components. The cacheable=true attribute is a specific requirement for the wire service, as it indicates the method only reads data (it is idempotent) and can be safely cached on the client to improve performance and manage data provisioning reactively.

Why Incorrect

B. @RemoteAction is a legacy annotation used for Visualforce JavaScript remoting and is not applicable to Lightning Web Components.
C. @RemoteAction is the incorrect annotation for Lightning components; it is used for Visualforce pages to call Apex methods from JavaScript.
D. Using only @AuraEnabled exposes the method, but it can only be called imperatively from a component. The cacheable=true attribute is required for it to be used with the @wire service.

References

1. Salesforce Developer Documentation, Lightning Web Components Dev Guide, "Call Apex Methods". Under the section "Wire an Apex Method to a Property or Function", it states: "To wire an Apex method to a property, the Apex method must be cacheable. Set cacheable=true."

2. Salesforce Developer Documentation, Apex Developer Guide, "AuraEnabled Annotation". This section describes the (cacheable=true) parameter, specifying its use for methods that retrieve data and its requirement for being wired to a Lightning component property.

Scroll to Top