Newer Version Available
Execute a SOQL Query
Use the Query
resource to execute a SOQL
query that returns all the results in a single response, or if needed, returns part of
the results and an identifier used to retrieve the remaining results.
The following query requests the value from name fields from all Account records.
- Example usage for executing a query
-
1curl https://yourInstance.salesforce.com/services/data/v51.0/query/?q=SELECT+name+from+Account -H "Authorization: Bearer token" - Example request body for executing a query
- none required
- Example response body for executing a query
-
1{ 2 "done" : true, 3 "totalSize" : 14, 4 "records" : 5 [ 6 { 7 "attributes" : 8 { 9 "type" : "Account", 10 "url" : "/services/data/v51.0/sobjects/Account/001D000000IRFmaIAH" 11 }, 12 "Name" : "Test 1" 13 }, 14 { 15 "attributes" : 16 { 17 "type" : "Account", 18 "url" : "/services/data/v51.0/sobjects/Account/001D000000IomazIAB" 19 }, 20 "Name" : "Test 2" 21 }, 22 23 ... 24 25 ] 26}
Retrieving the Remaining SOQL Query Results
If the initial query returns only part of the results, the end of the response will
contain a field called nextRecordsUrl. For
example, you might find this attribute at the end of your
query:
1"nextRecordsUrl" : "/services/data/v51.0/query/01gD0000002HU6KIAW-2000"In such cases, request the next batch of records and repeat until all records have been retrieved. These requests use nextRecordsUrl, and do not include any parameters.
- Example usage for retrieving the remaining query results
-
1curl https://yourInstance.salesforce.com/services/data/v51.0/query/01gD0000002HU6KIAW-2000 -H "Authorization: Bearer token" - Example request body for retrieving the remaining query results
- none required
- Example response body for retrieving the remaining query results
-
1{ 2 "done" : true, 3 "totalSize" : 3214, 4 "records" : [...] 5}