lightning-datatable with the Lightning UI API for automatic field-level security and parallel updates.
Overview
This example demonstrates how to:- Enable inline editing on datatable columns
- Use
updateRecordfrom Lightning UI API - Update multiple records in parallel
- Import field references from schema
- Refresh data after successful updates
Component Code
JavaScript Controller
datatableInlineEditWithUiApi.js
Template
datatableInlineEditWithUiApi.html
Key Features
Schema Imports
Import field references to ensure correct API names:UI API Integration
Transform draft values into UI API format:Parallel Updates
Update multiple records simultaneously:Implementation Steps
- Import schema references - Import field API names from schema
- Define editable columns - Use schema references in fieldName
- Track draft values - Initialize
draftValues = []property - Handle save event - Transform drafts to UI API format
- Update records - Use
updateRecordwith Promise.all - Clear drafts - Reset
draftValuesafter save - Refresh data - Use
refreshApexto reload records - Show feedback - Dispatch toast events
UI API vs Apex Comparison
| Feature | UI API Approach | Apex Approach |
|---|---|---|
| Import Statements | Schema imports required | Not required |
| Update Method | updateRecord | Custom Apex method |
| Parallel Processing | Promise.all for concurrent updates | Single batch update |
| FLS Enforcement | Automatic | Manual |
| Custom Validation | Limited to standard rules | Full custom logic support |
| Performance | Parallel updates for speed | Single server call |
| Complexity | Lower (uses platform APIs) | Higher (custom code) |
Benefits of UI API
- Automatic Security: Field-level security enforced automatically
- Parallel Processing: Multiple records updated concurrently
- Standard Validation: Platform validation rules applied
- No Apex Code: Reduces custom code maintenance
- Type Safety: Schema imports prevent field name errors
When to Use
Choose UI API when:- Updates are simple field changes
- Standard validation rules are sufficient
- Parallel processing is beneficial
- Minimizing custom code is priority
- Complex business logic is required
- Custom validation is needed
- Multiple objects need updating
- Batch processing is more appropriate
Best Practices
- Always import field references from schema
- Use
slice()to avoid mutating original draft values - Implement proper error handling
- Clear
draftValuesbefore async operations - Use
Promise.allfor parallel updates - Provide user feedback with toast notifications
- Refresh wired data after successful updates
Related Components
Source
datatableInlineEditWithUiApi.js:7-11- Schema field importsdatatableInlineEditWithUiApi.js:13-37- Column definitions with schema referencesdatatableInlineEditWithUiApi.js:46-83- Save handler with UI API updates
