nerdexam
Salesforce

PDI · Question #184

A developer must perform a complex SOQL query that joins two objects in a Lightning component. How can the Lightning component execute the query?

The correct answer is B. Write the query in a custom Lightning web component wrapper ana invoke from the Lightning. To execute a complex SOQL query from a Lightning component, the query should be defined within a server-side Apex class that serves as a data wrapper and is invoked by the client-side component.

Submitted by kwame.gh· Apr 18, 2026User Interface

Question

A developer must perform a complex SOQL query that joins two objects in a Lightning component. How can the Lightning component execute the query?

Options

  • ACreate a flow to execjte the query and invoke from the Lightning component
  • BWrite the query in a custom Lightning web component wrapper ana invoke from the Lightning
  • CInvoke an Apex class with the method annotated as &AuraEnabled to perform the query.
  • DUse the Salesforce Streaming API to perform the SOQL query.

How the community answered

(28 responses)
  • A
    18% (5)
  • B
    71% (20)
  • C
    7% (2)
  • D
    4% (1)

Why each option

To execute a complex SOQL query from a Lightning component, the query should be defined within a server-side Apex class that serves as a data wrapper and is invoked by the client-side component.

ACreate a flow to execjte the query and invoke from the Lightning component

While a flow can execute SOQL queries and be invoked from a Lightning component, this approach adds an extra layer of abstraction and is typically less direct or efficient for fetching complex data for a component compared to a dedicated Apex controller.

BWrite the query in a custom Lightning web component wrapper ana invoke from the LightningCorrect

A Lightning component, being a client-side technology, cannot directly execute SOQL queries. Therefore, the complex SOQL query must be written in an Apex class that acts as a server-side data wrapper or controller specifically for the Lightning web component, and then this Apex method is invoked from the client-side component to fetch the data.

CInvoke an Apex class with the method annotated as &AuraEnabled to perform the query.

Invoking an Apex class method annotated as `@AuraEnabled` is the standard and correct way to execute SOQL from a Lightning component. However, if 'B' is chosen, it implies a more specific 'wrapper' architecture for the component's data layer.

DUse the Salesforce Streaming API to perform the SOQL query.

The Salesforce Streaming API is designed for receiving real-time event notifications and is not used for performing ad-hoc SOQL queries to retrieve data for display in a component.

Concept tested: Lightning component server-side data access (Apex)

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

Topics

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

Community Discussion

No community discussion yet for this question.

Full PDI Practice