PDI · Question #106
Refer to the code snippet below: When a Lightning web component is rendered, a list of apportunities that match certain criteria shopuld be retrievved from the database and displayed to the end…
The correct answer is A. The method must specify the (cacheable-trun) attribute D. The method cannot mutate the result set retrieved from the database. E. The method must be annotated with the AureEnabled annolation. For an Apex method to be consumable by a Lightning Web Component, it must be annotated with @AuraEnabled, marked cacheable=true for client-side caching, and cannot mutate the retrieved result set if it's cacheable.
Question
Refer to the code snippet below:
When a Lightning web component is rendered, a list of apportunities that match certain criteria shopuld be retrievved from the database and displayed to the end user. Which three Considerations must the developer implement to make the method available within the Lightning web component? Choose 3 answer
Options
- AThe method must specify the (cacheable-trun) attribute
- BThe method must specify the (continuation-true) attribute
- CThe method must be annotaled with true Invocablemethod annolation
- DThe method cannot mutate the result set retrieved from the database.
- EThe method must be annotated with the AureEnabled annolation
How the community answered
(47 responses)- A96% (45)
- B2% (1)
- C2% (1)
Why each option
For an Apex method to be consumable by a Lightning Web Component, it must be annotated with `@AuraEnabled`, marked `cacheable=true` for client-side caching, and cannot mutate the retrieved result set if it's `cacheable`.
The `@AuraEnabled(cacheable=true)` annotation allows the method to be cached on the client-side, which improves performance for read-only operations by reducing server round trips.
The `(continuation=true)` attribute is not a standard `@AuraEnabled` parameter for LWC methods; continuations are a specific feature for calling external web services with long-running requests in Apex.
The `@InvocableMethod` annotation is used for exposing Apex methods to Salesforce flows, processes, or other invocable contexts, not directly to Lightning web components.
An `@AuraEnabled(cacheable=true)` method cannot mutate the data it retrieves or performs DML operations, as caching implies a read-only idempotent operation; if it were to mutate data, the cached result would be stale.
The `@AuraEnabled` annotation is mandatory for any Apex method that needs to be called from a Lightning component (LWC or Aura) to expose it to the client-side controller.
Concept tested: Apex for Lightning Web Components
Source: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_call_server_methods
Topics
Community Discussion
No community discussion yet for this question.