nerdexam
Salesforce

PDI · Question #8

A developer migrated functionality from JavaScript Remoting to a Lightning web component and wants to use the existing getOpportunities() method to provide data. What to do now?

The correct answer is A. The method must be decorated with (cacheable=true).. The developer needs to use an existing Apex method to provide data to a Lightning Web Component via a wired property, after migrating from JavaScript Remoting.

Submitted by anjalisingh· Apr 18, 2026User Interface

Question

A developer migrated functionality from JavaScript Remoting to a Lightning web component and wants to use the existing getOpportunities() method to provide data. What to do now?

Options

  • AThe method must be decorated with (cacheable=true).
  • BThe method must be decorated with @AuraEnabled.
  • CThe method must return a JSON Object.
  • DThe method must return a String of a serialized JSON Array.

How the community answered

(49 responses)
  • A
    92% (45)
  • B
    4% (2)
  • C
    2% (1)
  • D
    2% (1)

Why each option

The developer needs to use an existing Apex method to provide data to a Lightning Web Component via a wired property, after migrating from JavaScript Remoting.

AThe method must be decorated with (cacheable=true).Correct

For an Apex method to be correctly used by a Lightning Web Component with a wired property for data retrieval, it must be annotated with `@AuraEnabled(cacheable=true)` to enable client-side caching, which improves component performance.

BThe method must be decorated with @AuraEnabled.

While `@AuraEnabled` is necessary, `(cacheable=true)` is also required specifically for methods invoked by wired properties in LWC to enable efficient client-side caching.

CThe method must return a JSON Object.

Apex methods invoked by LWCs typically return Apex data types (e.g., `List<Opportunity>`) that are automatically serialized to JSON, rather than explicitly returning a `JSON Object` string.

DThe method must return a String of a serialized JSON Array.

Apex methods invoked by LWCs typically return native Apex data types, and Salesforce handles the serialization to JSON automatically, so returning a serialized JSON Array string is not necessary or the standard practice.

Concept tested: Apex @AuraEnabled(cacheable=true) for LWC wire service

Source: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.apex_wire_method

Topics

#Lightning Web Components#Apex Integration#AuraEnabled#Data Retrieval

Community Discussion

No community discussion yet for this question.

Full PDI Practice