Learn the correct annotation to make an Apex method available for Lightning web components in the Salesforce CRT-450 certification exam. Discover the difference between @AuraEnabled and @RemoteAction annotations.
Table of Contents
Question
A developer wrote an Apex method to update a list of Contacts and wants to make it available for use by Lightning web components.
Which annotation should a developer add to the Apex method to archive this?
A. @RemoteAction(cacheable=true)
B. @AuraEnabled
C. @RemoteAction
D. @AuraEnabled(cacheable=true)
Answer
D. @AuraEnabled(cacheable=true)
Explanation
To make an Apex method available for use by Lightning web components, the @AuraEnabled annotation should be added to the method. The cacheable=true parameter enables client-side caching of the method’s return value, which can improve performance by reducing the number of server round trips.
The @RemoteAction annotation is used for making Apex methods available to JavaScript code in Visualforce pages, not Lightning web components. The cacheable parameter is not applicable to @RemoteAction.
Therefore, the correct annotation to add to the Apex method for use by Lightning web components is @AuraEnabled(cacheable=true).
Salesforce Certified Platform Developer I CRT-450 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Salesforce Certified Platform Developer I CRT-450 exam and earn Salesforce Certified Platform Developer I CRT-450 certification.