Newer Version Available
Step 6: Query Jobs
-
Create the job.
URI
1/services/data/v65.0/jobs/queryExample of creating a bulk query job
1curl https://MyDomainName.my.salesforce.com/services/data/v65.0/jobs/query -H 'Content-Type: application/json' -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "X-PrettyPrint:1" --data-raw '{ "operation" : "query", "query" : "SELECT Id, Name FROM Account" } ' -X POSTThe response includes the job id and shows the job’s state as UploadComplete. (You use the job id to monitor the job or get its results.)
Example response body
1{ 2 "id" : "7986gEXAMPLE4X2OPT", 3 "operation" : "query", 4 "object" : "Account", 5 "createdById" : "0055fEXAMPLEtG4AAM", 6 "createdDate" : "2022-01-02T17:38:59.000+0000", 7 "systemModstamp" : "2022-01-02T17:38:59.000+0000", 8 "state" : "UploadComplete", 9 "concurrencyMode" : "Parallel", 10 "contentType" : "CSV", 11 "apiVersion" : 65.0, 12 "lineEnding" : "LF", 13 "columnDelimiter" : "COMMA" 14} -
Monitor the job’s state using the returned job id.
URI
1/services/data/v65.0/jobs/query/queryJobIdExample of monitoring the state of the query job
1curl https://MyDomainName.my.salesforce.com/services/data/v65.0/jobs/query/7986gEXAMPLE4X2OPT -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "X-PrettyPrint:1" -X GETExample response body
The response shows the current state of the job. Repeat this step until the state is JobComplete.
1{ 2 "id" : "7986gEXAMPLE4X2OPT", 3 "operation" : "query", 4 "object" : "Account", 5 "createdById" : "0055fEXAMPLEtG4AAM", 6 "createdDate" : "2022-01-02T17:38:59.000+0000", 7 "systemModstamp" : "2022-01-02T17:39:00.000+0000", 8 "state" : "JobComplete", 9 "concurrencyMode" : "Parallel", 10 "contentType" : "CSV", 11 "apiVersion" : 65.0, 12 "jobType" : "V2Query", 13 "lineEnding" : "LF", 14 "columnDelimiter" : "COMMA", 15 "numberRecordsProcessed" : 28, 16 "retries" : 0, 17 "totalProcessingTime" : 153, 18 "isPkChunkingSupported": true 19} -
Get the results of the job.
URI
1/services/data/v65.0/jobs/query/queryJobId/resultsExample of getting the results of the job
1curl https://MyDomainName.my.salesforce.com/services/data/v65.0/jobs/query/7986gEXAMPLE4X2OPT/results/ -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "Content-Type: application/json; charset=UTF-8" -H "Accept: text/csv" -H "X-PrettyPrint:1" -X GETThe response shows the results of the SOQL query when you created the query job.
Example response body
1"Id","Name" 2"0015f00000BCvReAAL","Sample Account for Entitlements" 3"0015f00000BFjNuAAL","University of The Terrific" 4"0015f00000C6beUAAR","Edge Communications" 5"0015f00000C6beVAAR","Burlington Textiles Corp of America" 6"0015f00000C6beWAAR","Pyramid Construction Inc." 7"0015f00000C6beXAAR","Dickenson plc" 8"0015f00000C6beYAAR","Grand Hotels & Resorts Ltd" 9"0015f00000C6beZAAR","United Oil & Gas Corp." 10"0015f00000C6beaAAB","Express Logistics and Transport" 11"0015f00000C6bebAAB","University of Arizona" 12"0015f00000C6becAAB","United Oil & Gas, UK" 13"0015f00000C6bedAAB","United Oil & Gas, Singapore" 14"0015f00000C6beeAAB","GenePoint"This example returns a small result set, and it’s easy to see the complete results. Queries that return larger results spread them across a sequence of result sets. To see the other result sets, use the locator to fetch the next set of results. For more information, see Get Results for a Query Job.