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 questionsTo 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.
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.
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.
Keep practicing
Take the free Plat-Dev-201 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Plat-Dev-201 practice questions
- Question 1Which three steps allow a custom Scalable Vector Graphic (SVG) to be included in a Lightn…
- Question 2Which two statements are true about using the @testSetup annotation in an Apex test class…
- Question 3Managers at Universal Containers want to ensure that only decommissioned containers are a…
- Question 4Universal Containers has a Visualforce page that displays a table of every Container__c b…
- Question 5A developer is alerted to an issue with a custom Apex trigger that is causing records to …
- Question 6Which two operations affect the number of times a trigger can fire? Choose 2 answers
