Advanced 15 min read

Why Apex Needs to Talk to the UI

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

  • Explain what a Lightning Web Component is, at a high level
  • Recognize why Apex methods need special exposure to be called from the UI
  • Understand the boundary this module focuses on: the Apex side only

Prerequisites: Module 33: "Debugging Like a Professional"

What an LWC is, briefly

A Lightning Web Component is a reusable piece of UI — a button, a form, a data table — built with standard JavaScript, HTML, and CSS, running inside Salesforce. Every custom controller method Module 30's "Secure Apex Controllers" lesson previewed exists specifically to be called from components like these.

Why a regular Apex method isn't automatically callable from the UI

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

A perfectly ordinary Apex method like this cannot be called from an LWC as written — Apex methods need to be explicitly exposed for that purpose, exactly the way a public field (Module 10) needed explicit access before code outside its class could touch it. The next lesson covers exactly how.

This module's scope: the Apex side only

This is a course about Apex — it doesn't cover writing the JavaScript and HTML that make up an LWC itself. This module focuses entirely on the boundary: what an Apex method needs to look like, and how it needs to behave, to be safely and correctly callable from a component someone else builds. Every lesson from here treats "an LWC calls this method" as a given, not something this module teaches how to write.

Exercise

As a comment, explain why AccountController.getAccounts() as shown cannot be called directly from an LWC.

Show hint

Think about what Module 10's access modifiers taught about explicit exposure.

APEX

Why Apex Needs to Talk to the UI Quiz

1. What does this module cover, specifically?

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

A Lightning Web Component (LWC) is Salesforce's modern UI framework — this module covers exactly the Apex-side boundary that lets an LWC call into Apex code, not LWC's own JavaScript and HTML.