Intermediate 15 min read

Lightning Data Service and the UI API

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

  • Explain what Lightning Data Service (LDS) is and what it wraps
  • Understand why LDS often eliminates the need for custom Apex
  • Recognize the limits of what LDS alone can do

Prerequisites: Module 5: "Project: Components That Talk to Each Other"

What Is Lightning Data Service?

Lightning Data Service (LDS) is a client-side data layer built into LWC that lets components read and write Salesforce records without writing any Apex at all. It's built on top of Salesforce's UI API — the same REST API Lightning Experience's own record pages use internally.

The UI API

The UI API is a general-purpose REST API for working with Salesforce records, fields, and layouts. LDS is effectively a JavaScript wrapper around calling this API correctly — handling the request shape, caching results, and enforcing security for you.

Why LDS Often Beats Custom Apex

  • Shared caching — if two unrelated components on the same page both need the same record via LDS, only one server call actually happens; the cache is shared.
  • Automatic security enforcement — field-level security and sharing rules are respected automatically, with zero extra code required.
  • Less code to write and maintain — no controller class, no test class, no deployment of Apex at all for straightforward record access.

When LDS Isn't Enough

LDS handles straightforward record CRUD well, but it isn't a replacement for complex business logic, aggregations across many records, or org-specific validation that can't be expressed declaratively. Module 7 covers exactly when reaching for Apex instead is the right call.

Exercise

Explain, as a comment, why two unrelated components on the same page both requesting the same Account record via LDS results in only one server call.

Show hint

Think about what LDS shares across components.

JAVASCRIPT

Exercise

Challenge: describe a realistic scenario where LDS alone would NOT be sufficient, and Apex would genuinely be needed.

Show hint

Think about logic that spans multiple records or complex business rules.

JAVASCRIPT

Lightning Data Service and the UI API Quiz

1. What does Lightning Data Service let a component do without writing Apex?

2. What API does LDS build on top of?

3. LDS automatically enforces field-level security and sharing rules.

4. What happens when two different components on the same page request the same record via LDS?

5. Which scenario is a genuinely good reason to reach for Apex instead of LDS alone?

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

Lightning Data Service lets components read and write Salesforce records with zero Apex — automatic caching, sharing, and field-level security enforcement, all built in.