No more Apex wrappers for basic DML. executeMutation brings full record write operations directly to your LWC JavaScript.
The GraphQL wire adapter in LWC has been great for reading data reactively. But write operations — creating, updating, deleting records — still needed Apex. That changes now. executeMutation from lightning/graphql brings full DML capability directly to LWC JavaScript, no Apex required.
What's New
According to the official Salesforce Developer Blog, GraphQL mutations are now available in LWC. Salesforce introduced the newest version of the GraphQL wire adapter (lightning/graphql) in Winter '26. This release adds support for using GraphQL beyond just querying — adding the ability to create, update, and delete records via the GraphQL Mutations API.
This fully unlocks bulk updates and tree saves for LWC without custom Apex, bringing richer data-driven applications to life.
The Core Function: executeMutation
According to the official executeMutation API reference, you import executeMutation from lightning/graphql and call it imperatively. It accepts an object with three properties:
| Property | Required | Description |
|---|---|---|
query | Yes | Parsed GraphQL mutation query. Must be parsed using the gql template literal function. |
variables | No | An object providing GraphQL variables. Must include an input argument with the record Id and fields. |
operationName | No | Selects which operation to run if the query defines more than one. Recommended for server-side debugging. |
executeMutation is not supported with the @wire annotation. You call it imperatively from a JavaScript function — typically on button click or form submit. The return value includes data and errors (plural — not error).Create a Record
When creating a record, include all required fields, include only createable fields, and assign IDs to Reference fields using their API name. According to the official docs, use the refresh method after creation to ensure new records appear in existing query results.
Update a Record
When updating, include the ID of the record, include only updateable fields, and assign Reference field IDs using their API name. The output field is Record. According to the official docs, use refresh to ensure updated records are reflected in existing query results — though the official blog notes that updated field values may propagate to subscribed LDS wire adapters automatically when cached data overlaps.
Delete a Record
When deleting, include only the ID of the record. According to the official docs, deleted records are properly removed from LDS wire results automatically — no manual refresh required.
Data Consistency: When to Refresh
According to the official Salesforce Developer Blog, Lightning Data Service keeps record data consistent across UIAPI and GraphQL — but there are some important nuances:
| Operation | Refresh needed? | Notes |
|---|---|---|
| Create | Yes | New records won't appear in existing query results until refreshed |
| Update | Sometimes | Updated fields may propagate automatically when cached data overlaps. Not always required. |
| Delete | No | Deleted records are properly removed from LDS wire results automatically |
GraphQL Mutations vs. Apex DML — When to Use Each
| Scenario | Use GraphQL Mutations | Use Apex |
|---|---|---|
| Create / update / delete UI API-supported sObjects | ✅ Yes | Works too, more boilerplate |
| Bulk operations on multiple records | ✅ Multiple mutations in one call | ✅ Also works |
| Complex business logic before/after DML | ❌ Not ideal | ✅ Right choice |
| Non-UI-API supported objects | ❌ Not supported | ✅ Required |
| Mobile Offline use cases | ❌ Not supported | ✅ Required |
| Child relationship creation in one operation | ❌ Not supported | ✅ Required |
Key Takeaways
- Import
executeMutationandgqlfromlightning/graphql - Always imperative —
@wireis not supported for mutations - Returns
{ data, errors }— checkerrors(plural, array) noterror - Create: include all required fields + call
refreshto update query results - Update: include record
Id+ updateable fields only +refreshif needed - Delete: include
Idonly — LDS removes it from wire results automatically - Child relationship nesting in a single mutation is not supported
- UI API-supported sObjects only — use Apex for everything else
- Use
operationNamefor cleaner server-side debugging
GraphQL mutations complete the picture for data management in LWC. You can now read and write Salesforce data entirely through GraphQL without a single line of Apex for straightforward CRUD operations. That's a meaningful shift in how you architect LWC components for data-heavy UIs.
📄 Sources: GraphQL Mutations Now Available in LWC — Salesforce Developer Blog | executeMutation — LWC API Reference | SalesforceBolt GitHub — graphql-mutations


0 Comments