Salesforce API tip: REST Query (SOQL) Limit

While developing a mobile application for the iPhone using the Salesforce Mobile SDK (which utilises the Salesforce REST API), we encountered an issue with retrieving a large batch of data.


The mobile app retrieves the data from Salesforce by using SOQL (SFRestAPI::requestForQuery function) and displays the data as a list. Everything was working fine until we performed a stress test to retrieve 10,000 contact records from Salesforce.


We realized that the requestForQuery REST operation only returned the first 2000 records.


After doing some research, we found that we needed to do a continuous call by using the nextRequestsUrl field returned in the REST call response with SFRestRequest::requestWithMethod function to retrieve the next 2000 records. Below is how we handled it in Xcode:
//retrieve the value of nextRecordUrl from the response
NSString *nextRecordURL = [response objectForKey:@"nextRecordsUrl"];

//only do the next call if there are more records
if([nextRecordURL length] > 0){
   nextRecordURL = [nextRecordURL stringByReplacingOccurrencesOfString:@"/services/data" withString:@""];
   SFRestRequest *test = [SFRestRequest requestWithMethod:SFRestMethodGET path:nextRecordURL queryParams:nil];
   [[SFRestAPI sharedInstance] send:test delegate:self];
I hope that is helpful if you are looking to retrieve large sets of data.