Apex for page components: controllers and wire adapters
Which Apex contract each page component needs: @AuraEnabled methods called by wire or imperatively from Lightning web components, cacheable=true and refreshApex, AuraHandledException errors, @InvocableMethod actions shared by Flow and Agentforce, and Visualforce standard, list, custom and extension controllers.
Given a scenario, implement Apex to work with various types of page components, including Lightning components, Flow, and Agentforce.
~7 min read · 20 practice questions ·
What the exam expects
- Expose an Apex method to a Lightning web component and choose between
@wireand an imperative call. - Explain what
cacheable=trueallows and forbids, and refresh stale wired data withrefreshApex(). - Return controlled errors from Apex with
AuraHandledExceptionand handle them in the component. - Write one
@InvocableMethodthat a flow and an Agentforce agent can both call, with clear labels and a bulk-safe signature. - Pick the Visualforce controller type: standard, standard list, custom or extension.
Key terms: @AuraEnabled (the annotation that exposes a static Apex method to Lightning components), cacheable method (a read-only @AuraEnabled method whose results the client caches), imperative call (a promise-returning call your code triggers), invocable action (an @InvocableMethod that Flow, agents and REST can run), controller extension (an Apex class that extends a standard or custom Visualforce controller).
Key facts
- Detail
static,publicorglobal,@AuraEnabled
- Detail
- Not allowed on
@AuraEnabledmethods from API 55.0
@wire to Apex- Detail
- Requires
cacheable=true; the method can't change data
- Detail
refreshApex()with the wire-emitted value
- Detail
- Only
@AuraEnabledmembers are returned
- Detail
- Throw
AuraHandledExceptioninstead of a raw system exception
- Detail
- One method; only
@Deprecatedmay accompany it
- Detail
- At most one List parameter; outputs match inputs in size and order
- Detail
- Method and variable labels and descriptions become the action's defaults
- Detail
- 20 records by default
- Detail
- Run in system mode; standard controller logic runs in user mode
Sources for this section (9)
- Expose Apex Methodsdeveloper.salesforce.com (opens in a new tab)
- AuraEnabled Annotationdeveloper.salesforce.com (opens in a new tab)
- Client-Side Cachingdeveloper.salesforce.com (opens in a new tab)
- Returning Data from Apexdeveloper.salesforce.com (opens in a new tab)
- Returning Errors from Apexdeveloper.salesforce.com (opens in a new tab)
- InvocableMethod Annotationdeveloper.salesforce.com (opens in a new tab)
- Agentforce Apex Actionsdeveloper.salesforce.com (opens in a new tab)
- Pagination with a List Controllerdeveloper.salesforce.com (opens in a new tab)
- Custom Controllers and Extensionsdeveloper.salesforce.com (opens in a new tab)
- Why can't a method that updates records be wired?
- When does a component need `refreshApex()`?
- Why label and describe an invocable method used as an agent action?
- Which Visualforce controller pages Opportunities 20 at a time with little Apex?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 21 lessons of the Platform Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (20 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams