Calling Apex from LWC and Aura components
How to read an LWC or Aura component and its Apex controller and spot the fix: cacheable wires versus imperative calls, reactive parameters and undefined values, refreshApex, immutable wired data, the Aura server-action lifecycle and the @AuraEnabled rules for methods and wrapper classes.
Given requirements and code snippets for a LWC or Aura Component and its Apex controller class, analyze determine any changes.
~8 min read · 11 practice questions ·
What the exam expects
- Read an LWC and its Apex method and decide whether the call must be wired or imperative, and what annotation the method needs.
- Spot parameter mistakes: a bare value instead of a parameter object, a missing
$, or anundefinedreactive value that stops the wire. - Refresh wired Apex data correctly with
refreshApex()and change provisioned data without mutating it. - Fix an Aura client-side controller that never reaches the server, or whose attribute change made outside the framework never rerenders.
- Apply the
@AuraEnabledrules for static methods, wrapper-class properties, unique action names and overloads.
Key terms: cacheable method (an @AuraEnabled(cacheable=true) method that only reads, required for @wire), reactive parameter (a $-prefixed wire parameter bound to a component property), wire-emitted value (the object the wire service provisions, which refreshApex() takes), server-side action (an Aura action created with component.get("c.method")), $A.getCallback() (the wrapper that brings code back into the Aura lifecycle).
The PD I basics (exposing methods, wire versus imperative in general, AuraHandledException) are in the Platform Developer guide's Apex for page components: controllers and wire adapters; this unit is the code-reading layer on top.
Key facts
@wire to Apex- Detail
- Method must be
@AuraEnabled(cacheable=true), static, public or global
- Detail
- May only get data, never change it
- Detail
- Must be called imperatively
- Detail
- An object whose properties match the Apex parameter names; Maps unsupported
undefined- Detail
- Method isn't called;
nullcalls it
refreshApex() argument- Detail
- An object previously emitted by an Apex
@wire
- Detail
- Treat as immutable; shallow-copy to change
- Detail
$A.enqueueAction(action)queues it; batched at end of event loop
- Detail
- SUCCESS, ERROR, INCOMPLETE (ABORTED deprecated)
setTimeout() in Aura- Detail
- Wrap in
$A.getCallback()so the component rerenders
- Detail
- Only
@AuraEnabledpublic instance members are returned
- Detail
- Not allowed on
@AuraEnabledmethods from API 55.0
Sources for this section (9)
- Wire Apex Methodsdeveloper.salesforce.com (opens in a new tab)
- Client-Side Cachingdeveloper.salesforce.com (opens in a new tab)
- Call Apex Methods Imperativelydeveloper.salesforce.com (opens in a new tab)
- Call Apex Methodsdeveloper.salesforce.com (opens in a new tab)
- Calling a Server-Side Actiondeveloper.salesforce.com (opens in a new tab)
- Action Statesdeveloper.salesforce.com (opens in a new tab)
- Outside the Framework Lifecycledeveloper.salesforce.com (opens in a new tab)
- Returning Data from Apexdeveloper.salesforce.com (opens in a new tab)
- AuraEnabled Annotationdeveloper.salesforce.com (opens in a new tab)
- Why does a wired Apex method that inserts records violate the platform's rules?
- When does a wire with a `$` parameter skip calling Apex?
- When does Aura code need `$A.getCallback()`?
- Which wrapper-class members reach the component?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer II pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the Platform Developer II guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (11 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams