Advanced 25 min read

@AuraEnabled Methods

By the end of this lesson, you'll be able to:

  • Mark an Apex method as callable from an LWC using @AuraEnabled
  • Explain why the method must be public or global and static
  • Recognize the annotation-based exposure pattern from Module 13

Prerequisites: "Why Apex Needs to Talk to the UI"

Marking a method as callable

public class AccountController {
    @AuraEnabled
    public static List<Account> getAccounts() {
        return [SELECT Id, Name FROM Account];
    }
}

@AuraEnabled above the method is exactly Module 13's annotation pattern — metadata telling the platform "this method may be called from a Lightning Web Component," without changing what the method's own code actually does.

Why public/global and static

@AuraEnabled
public static List<Account> getAccounts() { ... } // correct shape

@AuraEnabled
private List<Account> getAccounts() { ... } // will NOT work — private, and not static

An @AuraEnabled method must be public (or global, for methods exposed even outside the org, e.g. in a managed package) and static — the LWC framework calls it directly on the class, the same way TaxCalculator.applyVat(...) was called directly in Module 10, never on a specific object instance.

Exposing a parameterized method

public class AccountController {
    @AuraEnabled
    public static List<Account> searchAccountsByName(String searchTerm) {
        return [SELECT Id, Name FROM Account WHERE Name LIKE :('%' + searchTerm + '%')];
    }
}

Parameters work exactly like any other method (Module 9) — the LWC's JavaScript passes the argument when it calls into Apex, and everything from Module 20's bind-variable safety still applies unchanged.

Exercise

Add @AuraEnabled to expose this method to an LWC, correcting anything else needed to make it callable.

Show hint

It needs the annotation, and must be public and static.

APEX

@AuraEnabled Methods Quiz

1. What two requirements must an @AuraEnabled method's signature satisfy?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

@AuraEnabled is the annotation that exposes an Apex method to be called from an LWC — the exact "attach metadata above a method" pattern Module 13 first introduced.