import fetchOps from '@salesforce/apex/OpportunitySearch.fetchOpportunities';
@wire(fetchOps) opportunities;
When a Lightning web component is rendered, a list of opportunities that match certain criteria should be retrieved from the database and displayed to the end-user.
Which three considerations must the developer implement to make the fetchOpportunities method available when Lightning web component?
Show answerHide answer
Correct answer: A, C, D The method must be annotated with the @AuraEnabled annotationThe method cannot mutate the result set retrieved from the databaseThe method must specify the (cacheable=true) attribute.
Explanation
Explanation:Why these options are correct:
A. @AuraEnabled — Any Apex method that needs to be exposed to Lightning components, either through @wire or imperative calls, must be marked as static and annotated with @AuraEnabled.
C. Cannot mutate result set / read-only data — When data is provisioned through the wire service, the data stream is immutable, and Apex methods used with cacheable=true must be strictly read-only, meaning they cannot perform DML operations.
D. cacheable=true — To use an Apex method with the @wire service adapter, the @AuraEnabled annotation must explicitly include the cacheable=true attribute.
Why the other options are incorrect:
B. @InvocableMethod — This annotation is used to expose Apex methods to Salesforce Flow and other supported automation tools, not for LWC wire adapters.
E. continuation=true — Continuations are used for handling long-running callouts asynchronously in Apex controllers. They are not a mandatory requirement for standard component wiring.
References
Lightning Web Components Developer Guide: Wire an Apex Method
Lightning Web Components Developer Guide: Client-Side Caching of Apex Results


