function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jennifer BERNARDJennifer BERNARD 

All Query Jobs number of records in response (Bulk API 2.0)

Hello everyone.

I'm trying to get all jobs records using this URL:
https://my.org.my.salesforce.com/services/data/v58.0/jobs/query

According to the documentation I should be able to get 1000 records per request by default:
https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/query_get_all_jobs.htm?q=get%20all%20jobs

But when I run the query (using Postman), I get 200 records. How can I change the number of records in the response ?
Best Answer chosen by Jennifer BERNARD
Jennifer BERNARDJennifer BERNARD
Hello Swetha,

Thank you for you answer ! I have already tried setting maxRecords as a query parameters as followed:
/services/data/v58.0/jobs/query?maxRecords=1000
But got the following response (JSON):
[
    {
        "errorCode": "INVALID_QUERY_KEY",
        "message": "Found unexpected query key(s): maxRecords"
    }
]

I guess this is working only when we try to get the result of a Job, not when we retrieve all the jobs ?

SOLUTION: Actually, I've found how to retrieve 1000 records with each request, it's by using the API version 56.0 instead of 58.0. Apparently from API version 57.0, this request only retrieve 200 records by default. I will check the update releases pages for REST API to see if something can be done to filter the response with newer version, the documentation for Bulk API doesn't seem up-to-date yet.

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jennifer,
As explained in the Bulk API V2 “Get Results for a Query Job” document,(https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/query_get_job_results.htm) you need to use locator and maxRecords optional parameters to get query results.

For example, when you perform /services/data/v56.0/jobs/query/7507Q00000B4aRyQAJ/results GET call, it returns below response:
HTTP/1.1 200 OK
Date: Fri, 05 Jul 2023 13:29:10 GMT
Set-Cookie: CookieConsentPolicy=0:0; path=/; expires=Sat, 05-Jul-2024 13:29:10 GMT; Max-Age=31536000
Set-Cookie: LSKey-c$CookieConsentPolicy=0:0; path=/; expires=Sat, 05-Jul-2024 13:29:10 GMT; Max-Age=31536000
Strict-Transport-Security: max-age=63072000; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
Set-Cookie: BrowserId=LhVppNVIEe2eQGuk5rjRaA; domain=.salesforce.com; path=/; expires=Sat, 05-Jul-2024 13:29:10 GMT; Max-Age=31536000
Sforce-Limit-Info: api-usage=63138/1134000
Content-Type: text/csv
Sforce-Locator: MQ
Sforce-NumberOfRecords: 1
Vary: Accept-Encoding
Content-Encoding: gzip
Transfer-Encoding: chunked

Notice, Sforce-Locator: MQ and Sforce-NumberOfRecords: 1 in the response.

The locator value sent in the 1st set of results needs to be used in the subsequent call to get the next set of results until you see Sforce-Locator: null in the response.

For example, if you send /services/data/v56.0/jobs/query/7507Q00000B4aRyQAJ/results?locator=MQ GET call again, it results all the remaining results and you would notice Sforce-Locator: null in the response header which means all the records have been returned.
 
HTTP/1.1 200 OK
Date: Fri, 05 Jul 2023 13:32:05 GMT
Set-Cookie: CookieConsentPolicy=0:0; path=/; expires=Sat, 05-Jul-2024 13:32:05 GMT; Max-Age=31536000
Set-Cookie: LSKey-c$CookieConsentPolicy=0:0; path=/; expires=Sat, 05-Jul-2024 13:32:05 GMT; Max-Age=31536000
Strict-Transport-Security: max-age=63072000; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Robots-Tag: none
Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
Set-Cookie: BrowserId=lhG94dVIEe21Xk1uVGJuGg; domain=.salesforce.com; path=/; expires=Sat, 05-Jul-2024 13:32:05 GMT; Max-Age=31536000
Sforce-Limit-Info: api-usage=63398/1134000
Content-Type: text/csv
Sforce-Locator: null
Sforce-NumberOfRecords: 3796
Vary: Accept-Encoding
Content-Encoding: gzip
Transfer-Encoding: chunked

Apart from it, you can set maxRecords=maxRecords parameter to retrieve specific number of records, e.g. when I make /services/data/v56.0/jobs/query/7507Q00000B4aRyQAJ/results?maxRecords=1000 call, it returns 1000 records with Sforce-Locator: MTAw to retrieve next set of results.

Related:https://salesforce.stackexchange.com/questions/85967/rest-api-list-view-results-25-record-limit

If this information helps, please mark the answer as best. Thank you
Jennifer BERNARDJennifer BERNARD
Hello Swetha,

Thank you for you answer ! I have already tried setting maxRecords as a query parameters as followed:
/services/data/v58.0/jobs/query?maxRecords=1000
But got the following response (JSON):
[
    {
        "errorCode": "INVALID_QUERY_KEY",
        "message": "Found unexpected query key(s): maxRecords"
    }
]

I guess this is working only when we try to get the result of a Job, not when we retrieve all the jobs ?

SOLUTION: Actually, I've found how to retrieve 1000 records with each request, it's by using the API version 56.0 instead of 58.0. Apparently from API version 57.0, this request only retrieve 200 records by default. I will check the update releases pages for REST API to see if something can be done to filter the response with newer version, the documentation for Bulk API doesn't seem up-to-date yet.
This was selected as the best answer