You need to sign in to do that
Don't have an account?
Ashu sharma 38
How to retrieve more than 2000 records using resi api
Hi All,
I want to retrieve more than 2000 records in single response ,as I am using rest Api .
Any solutions ?
/services/data/v46.0/query/?q=Select Id,XXX__c,CompletedDateTime,XXX__c,WhoId from task WHERE CreatedDate > 2019-10-30T08:03:30.729Z and CreatedDate < 2019-10-30T18:33:30.729Z .
Thanks
I want to retrieve more than 2000 records in single response ,as I am using rest Api .
Any solutions ?
/services/data/v46.0/query/?q=Select Id,XXX__c,CompletedDateTime,XXX__c,WhoId from task WHERE CreatedDate > 2019-10-30T08:03:30.729Z and CreatedDate < 2019-10-30T18:33:30.729Z .
Thanks
There are lots of questions about it already, including some language-specicic answers (if you're using the libraries for Ruby for example). And there are even better ones at salesforce.stackexchange.com:
https://salesforce.stackexchange.com/questions/35011/get-more-than-2000-with-soap-and-php
Check https://salesforce.stackexchange.com/questions/924/is-there-a-way-to-query-role-hierarchy too
And if you have thousands of records (and if your app can handle bigger chunks!) maybe you should read about bulk API.
Please refer to these links it may help you find the best solution.
http://stackoverflow.com/questions/24321382/salesforce-query-returns-only-2000-data
https://salesforce.stackexchange.com/questions/169188/fetch-more-than-2000-records/169214
https://salesforce.stackexchange.com/questions/35011/get-more-than-2000-with-soap-and-php
Check https://salesforce.stackexchange.com/questions/924/is-there-a-way-to-query-role-hierarchy too.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I've gone through your requirement and you can see the below apex code to get more than 2000 record:
1.While OFFSET is limited to a total of 2,000 records, query & queryMore can be configured to return 2,000 records each call.
To do this, you need to first set the batch size for your connection via:
2.connection.setQueryOptions(2000);
3.Then, you need to call query, and return the first 2,000 records. The return value of query is a QueryResult, which contains the results, as well as a QueryLocator. The QueryLocator can be provided to the queryMore call to essentially perform an identical function as OFFSET, but supports a much higher number of records.
QueryResult = connection.queryMore(QueryLocator someQueryLocator);
4.From here, you repeat calls to queryMore, using the QueryLocator returned in the QueryResult from each call. Once the value of QueryResult.done is equal to true, you've retrieved all of the results from Salesforce, and can continue doing whatever your java app was doing.
I've included the example code from the documentation below, which uses query, and queryMore to fetch a large number of records from the database.
Apex Code--->
public void queryRecords() {
QueryResult qResult = null;
try {
String soqlQuery = "SELECT FirstName, LastName FROM Contact";
qResult = connection.query(soqlQuery);
boolean done = false;
if (qResult.getSize() > 0) {
System.out.println("Logged-in user can see a total of "
+ qResult.getSize() + " contact records.");
while (!done) {
SObject[] records = qResult.getRecords();
for (int i = 0; i < records.length; ++i) {
Contact con = (Contact) records[i];
String fName = con.getFirstName();
String lName = con.getLastName();
if (fName == null) {
System.out.println("Contact " + (i + 1) + ": " + lName);
} else {
System.out.println("Contact " + (i + 1) + ": " + fName
+ " " + lName);
}
}
if (qResult.isDone()) {
done = true;
} else {
qResult = connection.queryMore(qResult.getQueryLocator());
}
}
} else {
System.out.println("No records found.");
}
System.out.println("\nQuery successfully executed.");
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Thank you for the brief overview....
Have a question : Where can i write connection.setQueryOptions(2000); to set the batch size ?
Can you share whole code snippet so that i can reffer, it will help me to get through if you can ?