Query and Update Records with GraphQL Mutations in LWC
Learn how to query and modify records across sObjects with JavaScript using GraphQL. Build faster, simpler components while leveraging Lightning Data Service caching.
on this event will receive a $5 Starbucks gi card.* 1. Download the Salesforce Events mobile app. 2. Navigate to surveys. 3. Complete (4) session surveys and the Event Survey. 4. Redeem your gift at Badge Pickup in-person on the last day of the event. *Restrictions apply. See terms and conditions at sforce.co/survey-terms
API • Created by Facebook in 2012 • No need to call several APIs • Get many resources in a single request • Ask for what you need, get exactly that • Self documented • With a type system source: Michael Poirier-Ginter Fabien Taillon - Texeï
• A read only stream of data Shared cache between components (standard & custom) Reactive to changes outside of the component’s scope No Apex with standard Lightning Data Service Wire Adapters Just import it and use it 🚀 import { LightningElement, api, wire } from 'lwc'; import { getRecord } from 'lightning/uiRecordApi'; export default class Record extends LightningElement { @api recordId; @wire(getRecord, { recordId: '$recordId', fields: ['Account.Name'] }) record; } Fabien Taillon - Texeï
Query Any List of Records Easy to Use Powerful for Custom LWC • Order them • Group them • … • you don’t need to write any Apex • a list of all contacts for a given account • respects user Field Level Security • a search page • a hierarchy of records • one specific record with filters, without knowing its Id at first • … • Fabien Taillon - Texeï use the same shared Lightning Data Service cache
new features • • • • • Same gql, same @wire(graphql), same data & errors New: @optional fields, partial results instead of a failed query New: dynamic queries, ${} interpolation, fragments, variables in @skip / @include New: refresh() on the wire result, refreshGraphQL() is deprecated New: executeMutation • Keep the old module only for Mobile Offline • One module per project, don't mix Fabien Taillon - Texeï
have, with schema docs and autocomplete • Get an access token ◦ for instance use sf org auth show-access-token • New > GraphQL request, with the url: ◦ https://{MyDomainName}.my.salesforce.com/services/data/v{version}/graphql ◦ Authorization tab: Bearer Token ◦ Headers tab: X-Chatter-Entity-Encoding = false • The schema loads by itself, then you can: ◦ browse types and fields, tick them to build the query ◦ autocomplete, look at the API documentation, use variables Fabien Taillon - Texeï
executeMutation from lightning/graphql ◦ GA in Spring '26, supersedes lightning/uiGraphQLApi • Imperative only: call it from a handler, no @wire • Same GraphQL API as the wire ◦ respects CRUD & Field Level Security ◦ shares the Lightning Data Service cache • Returns { data, errors } Fabien Taillon - Texeï
operations in one mutation document Mix Create / Update / Delete, across sObject types Atomic or not: uiapi(input: { allOrNone: true }) Chained: "@{account}" references an earlier operation's result ◦ @{ref} since v59, @{ref.Record.Id} and @{ref.Record.Name.value} since v67 ◦ the referenced operation must come first • Nested child payloads are NOT supported ◦ no sObject Tree style: Account with an embedded Contacts array Fabien Taillon - Texeï
after a mutation • The graphql wire result now exposes refresh() ◦ no more refreshApex • Delete: the record disappears from wire results automatically • Create / Update: call refresh() • Query back the fields you changed in Record { ... } ◦ LDS ingests them: lightning-record-view-form, getRecord... update with zero code Fabien Taillon - Texeï
imperative only • No Mobile Offline support for lightning/graphql • No nested child payloads in an input • No child relationships in a mutation selection set Fabien Taillon - Texeï
experience-lds-graphql-generate ◦ introspects the org schema, generates a read or mutation, tests it against the org ◦ npx skills add forcedotcom/sf-skills • Salesforce MCP, lwc-experts toolset (beta) ◦ fetch_lds_graphql_schema, create_lds_graphql_mutation_query, test_lds_graphql_query • Claude Code salesforce-development plugin for the rest of the cycle ◦ scratch orgs, deploy, tests, code analyzer… Fabien Taillon - Texeï
on this event will receive a $5 Starbucks gi card.* 1. Download the Salesforce Events mobile app. 2. Navigate to surveys. 3. Complete (4) session surveys and the Event Survey. 4. Redeem your gift at Badge Pickup in-person on the last day of the event. *Restrictions apply. See terms and conditions at sforce.co/survey-terms