Sitemap
Sumanta Satpathy

Sumanta Satpathy

18X Certified Salesforce Architect | Driving Digital Transformation with Salesforce at LTA | Sharing insights on Nonprofit Cloud, Marketing Cloud & Agentforce

Why Use LDS Over Custom Apex?

2 min readMar 3, 2025

--

Press enter or click to view image in full size

What is LightningData Service?

LDS is like the“Data Layer” for Lightning Web Components (and Aura): it automatically handles caching, data consistency, and field-level security checks. With a set of base components and JavaScript

Get Sumanta Satpathy’s stories in your inbox

Join Medium for free to get updates from this writer.

APIs, you can:

  1. Fetch record details
  2. Edit fields directly
  3. Listen for changes
  4. Re-render your UI whenever underlying dataupdatesAll

All of this occurs without writing custom Apex or manual server calls.

Why Use LDS OverCustom Apex?

  1. No Apex Classes Needed: Declaratively retrieving or updating records cuts down on code complexity and deployment overhead.
  2. Built-In Caching: LDS caches data locally. If multiple components request the same record, they all share that cache, reducing server calls and improving performance.
  3. Automatic FLS & Sharing Enforcement: Ensures you only fetch and modify fields the user has permission to access — without extra lines of code to handle security.
  4. Reduced Governor Limit Pressure: Fewer round trips to the server means less chance of hitting SOQL or CPU time limits, especially in data-heavy apps.

Practical Usage

Fetching a Record with lightning/uiRecordApi:

Press enter or click to view image in full size

Performance Tips

  1. Group Fields: Only request necessary fields (e.g., Account.Name &Account.Industry) to avoid fetching large amounts of data you don’t use.
  2. Leverage Caching: If you have multiple components referencing the same record via LDS, they share the record data under the hood, cutting down server calls.
  3. Combine with Apex for Complex Logic: If you do need advanced logic or multiple related objects, consider a hybrid approach, use LDS for the straightforward record fetch, and then custom Apex for specialized tasks.
  4. Watch Query Limits: Even though you’re not writing SOQL in your component, behind the scenes it’s still a query. Avoid wiring too many records or you risk performance hits.

--

--

Sumanta Satpathy
Sumanta Satpathy

Written by Sumanta Satpathy

18X Certified Salesforce Architect | Driving Digital Transformation with Salesforce at LTA | Sharing insights on Nonprofit Cloud, Marketing Cloud & Agentforce