getRecords

Use this wire adapter to get data for a batch of records at once. You can request multiple objects or different record types.

The getRecords wire adapter uses this User Interface API resource, but doesn’t support all its parameters.

  • records—An array of record data, which can be across multiple objects or record types.

  • recordIds—(At least one required) The ID of records to fetch from supported objects.

  • fields—An array of fields to return. If the context user doesn’t have access to a field, an error is returned. If you’re not sure whether the context user has access to a field and you don’t want the request to fail if they don’t, use the optionalFields parameter.

    Specify field names in the format ObjectApiName.FieldName or ObjectApiName.JunctionIdListName.

    Polymorphic fields aren't supported. Including a polymorphic field in fields can result in an invalid field error.

  • optionalFields— (Optional) An array of optional field names. If a field is accessible to the context user, it’s included in the response. If a field isn’t accessible to the context user, it isn’t included in the response, but it doesn’t cause an error. Specify field names in the format ObjectApiName.FieldName or ObjectApiName.JunctionIdListName.

  • propertyOrFunction—A private property or function that receives the stream of data from the wire service. If a property is decorated with @wire, the results are returned to the property’s data property or error property. If a function is decorated with @wire, the results are returned in an object with a data property and an error property.

  • resultsBatch Results
  • hasErrorstrue if at least one of the results in the result set is an HTTP status code in the 400 or 500 range, or false otherwise.

To get data for a single record, use getRecord instead.

To filter by criteria and work with dynamic record IDs easily, consider using the GraphQL wire adapter instead.

This example loads several records using the record IDs. Replace the recordId value with your own.

Alternatively, you can request for records across multiple objects.

To work with dynamic record IDs, consider using the GraphQL wire adapter instead.

If you use the getRecords wire adapter with dynamic record IDs, we recommend that you create a parameterObject array that you can push your record parameters to as a single property. Using an array enables you to define record IDs and fields for multiple objects.

For example, you can retrieve contact IDs by account via an Apex controller and then pass them to the parameterObject array. You can create the array in connectedCallback or renderedCallback. You can also pass in your record parameters from a parent component to a child component that initializes the array.

This example shows how you can set up the parameterObject array. The IDs object contains IDs of contact records that you want to retrieve using the getRecords wire adapter.

When you call the wire adapter, the User Interface API composes a SOQL query for the request. This SOQL query has a limit of 100k characters. If you expect to exceed this limit, we recommend splitting the query into multiple queries and run them in batches.

getRecords returns errors in an error property. To display errors, you can use toasts provided by the lightning/platformShowToastEvent module with a Promise that includes then() and catch() blocks.