How do you perform imperative CRUD operations on records using lightning/uiRecordApi functions?
Answer
Basics: Use them for simple create, edit or delete actions in a component, such as a button that creates a Task. They return Promises. createRecord({ apiName, fields }) resolves with the new record (including id), updateRecord({ fields: { Id, ... } }) resolves with the updated record, and deleteRecord(recordId) resolves with no value.
How it works: Build fields with schema-imported field names (NAME_FIELD.fieldApiName) to stay refactor-safe. For updates the Id field is required in fields. The call runs through UI API on the server in its own transaction, then the LDS cache is updated so wired components on the page refresh automatically. Errors are rejected Promises with body.output.errors and body.output.fieldErrors.
Advanced / deep dive: Each call is one record and one transaction; there is no multi-record atomic save, so for batches or parent-child inserts that must succeed together use Apex (with Database methods and a savepoint if needed). updateRecord accepts a second clientOptions argument such as ifUnmodifiedSince to detect conflicting edits. Helper functions generateRecordInputForCreate, generateRecordInputForUpdate and createRecordInputFilteredByEditedFields build inputs from getRecordUi or getRecordCreateDefaults. UI API supports a subset of objects and field types, so some objects (and some fields) are not available. Triggers, flows, validation rules and duplicate rules still run server-side, so errors from them surface as field or page errors. Choose LDS for simple UI CRUD (no Apex test needed, cache-aware) and Apex for logic, bulk, callouts or system-mode needs, remembering that Apex with bypasses sharing deliberately.