Skip to main content
Lightning Data Service (LDS) provides a declarative way to work with Salesforce data in Lightning Web Components. It handles caching, change detection, and automatic UI updates.

Creating Records

Use createRecord from lightning/uiRecordApi to create new records imperatively.

Parameters

  • recordInput (Object): Contains the record data
    • apiName (String): The API name of the object (e.g., ‘Account’)
    • fields (Object): Key-value pairs of field API names and values

Return Value

Returns a Promise that resolves to an object containing the newly created record’s id and other metadata.

Deleting Records

Use deleteRecord from lightning/uiRecordApi to delete records. Combine with refreshApex to refresh cached data after deletion.

Parameters

  • recordId (String): The 15 or 18-character Salesforce record ID

Return Value

Returns a Promise that resolves when the record is successfully deleted.

Benefits

Automatic Caching

LDS automatically caches records and shares them across components

Change Detection

Components automatically update when underlying records change

No Apex Required

Perform CRUD operations without writing server-side code

Security Built-in

Respects field-level and object-level security automatically