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 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?
To make an Apex method available for use by Lightning web components, it should be annotated with @AuraEnabled. The @AuraEnabled annotation allows the method to be called directly from JavaScript in Lightning Components, including both Aura components and Lightning web components. Other annotations such as @RemoteAction are more suited for Visualforce pages and should not be used in this context.
The correct answer is B. Imperative apex method call needs to be anotaded with @AuraEnabled.
Why not B?
Its B as (cacheable=true) is not required to achieve the request. However, can be added if needed.
https://developer.salesforce.com/docs/platform/lwc/guide/apex-wire-method.html
No, you cannot perform update operations in an @AuraEnabled(cacheable=true) method. The @AuraEnabled(cacheable=true) annotation is used to indicate that the method's results can be cached on the client side for performance optimization. This implies that the method must be idempotent and should not change any data. It should be used for read-only operations. To perform update operations, you should use a standard @AuraEnabled method without the cacheable=true attribute. Here’s how you can do it: