Lightning Data Service (LDS) is a Salesforce-managed cache and CRUD layer for record data, accessible from LWC without writing Apex.
LDS provides:
- `getRecord` — fetch a record's fields with cached, FLS-aware results.
- `getRecordCreateDefaults` / `getRecordUi` — get layout-aware metadata for record creation/edit.
- `createRecord` / `updateRecord` / `deleteRecord` — CRUD without Apex.
- `getRecordNotifyChange` — invalidate cache to force refresh.
`javascript import { LightningElement, wire } from 'lwc'; import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = ['Account.Name', 'Account.Industry'];
export default class AccountView extends LightningElement { @api recordId; @wire(getRecord, { recordId: '$recordId', fields: FIELDS }) account; } `
When to use LDS: simple read/edit on a single record, you want FLS/sharing automatically respected, you don't need cross-object queries.
When to use Apex instead: complex SOQL (joins, aggregates), cross-object logic, custom business rules before save, bulk operations, integrations.
Bonus: LDS shares its cache across all components on a page, so multiple components viewing the same record share data without duplicate API calls.
