Reputation: 801
I was using simple-salesforce library to query the salesforce through REST API but getting query timeout error. I have not added the LIMIT keyword in the query as I thought salesforce will automatically only return 2000 result and after that, it will provide nextRecordURL for other 2000 records.
My Current implementation looks like this,
json_response = self.sf_api_instance.query_all_custom(query)
parent_mapper = SalesForceMapper(json_response, field_mapping=field_mapping)
self.send_data(parent_mapper, object_type)
is_done = json_response.pop("done", False)
next_records_url = json_response.pop("nextRecordsUrl", '')
if json_response["records"]:
self.processed_Ids[object_type] = json_response["records"][0]["Id"]
self.memorize(self.processed_Ids, self.username)
while True:
if not is_done:
json_response = self.sf_api_instance.query_more(next_records_url, True)
parent_mapper = SalesForceMapper(json_response, field_mapping=field_mapping)
self.send_data(parent_mapper, object_type)
is_done = json_response.pop("done", False)
next_records_url = json_response.pop("nextRecordsUrl", '')
else:
break
So is my understanding is right or I need to provide LIMIT in every query.
Upvotes: 0
Views: 618
Reputation: 976
It is most likely because your query isn't selective and taking a very long time to run. Follow the directions here to make your query selective. In short try not to use negative criteria in your where clause like <> or NOT IN and use indexed values. When you do that the query will execute quickly and not time out.
Upvotes: 1