Query Objects Examples

AVAILABLE API VERSION
API v56.0 and later
Optional fields available in API v65.0 and later

Use queries to load record data from Salesforce objects. Only objects supported by UI API are available for querying.

To query an object, request a field with the same name under the RecordQuery type. This example queries accounts with their IDs and names.

The query returns only objects and fields that the user has access to.

This example queries users with their IDs and employee numbers. The employee number field is marked as optional.

If the user executing the query has access to the employee number field, the query returns all the data as expected. If the user executing the query doesn’t have access to the employee number field, the query succeeds and returns the Id field but not the EmployeeNumber field or any subfields of EmployeeNumber.

You can query multiple objects in one call.

Send your query in a separate call if the query depends on a field or value from an earlier query. Alternatively, work with semi-joins or auto-joins to query parent and child relationships.

This example queries accounts and cases. The second query includes a semi-join using the reference field AccountId, which filters cases whose account parent records match the given Name pattern and Industry field value.

The query returns the first 10 results of each query.

The first query returns accounts with the Name and Industry fields, similar to this SOQL statement.

The second query is similar to this SOQL statement.

Multiple query execution where a query requires field or value dependencies on another query within the same execution isn’t supported.