Overview
ThegraphqlMultipleObjects component demonstrates how to query multiple unrelated object types in a single GraphQL query. This reduces the number of server requests and improves performance.
Source
force-app/main/default/lwc/graphqlMultipleObjects
Key Features
- Multiple object queries in single request
- Parallel data fetching
- Separate getters for each object type
- Unified error handling
Query Multiple Objects
Query Structure
Include multiple object types under the samequery block:
Separate Getters for Each Object
Create dedicated getters to transform data for each object type:Template Rendering
Render each object type separately:Unified Error Handling
Handle errors once for all queries:graphql.errors.
Benefits of Multiple Object Queries
Performance
Fetching multiple objects in a single query reduces:- Network round trips
- Server processing overhead
- Overall load time
Code Organization
A single wire adapter can provide data for:- Dashboard components displaying multiple object types
- Related lists from different objects
- Summary views with cross-object data
Consistency
All data is fetched at the same point in time, ensuring:- Consistent data snapshot
- Synchronized refresh
- Unified loading state
Different Parameters Per Object
Each object query can have unique parameters:When to Use Multiple Object Queries
- Building dashboards with data from multiple objects
- Displaying related but unconnected object types
- Reducing network overhead for initial page loads
- Creating summary or overview components
Limitations
While powerful, consider:- Total query complexity limits
- Individual object query limits
- Overall response payload size
