【问题标题】:Do we need to provide LIMIT in soql query while using REST API?使用 REST API 时是否需要在 sql 查询中提供 LIMIT?
【发布时间】:2018-03-22 10:21:49
【问题描述】:

我使用 simple-salesforce 库通过 REST API 查询 salesforce,但出现查询超时错误。我没有在查询中添加 LIMIT 关键字,因为我认为 salesforce 将自动只返回 2000 条结果,之后,它将为其他 2000 条记录提供 nextRecordURL。

我当前的实现是这样的,

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

我的理解是正确的还是我需要在每个查询中提供 LIMIT。

【问题讨论】:

    标签: python-2.7 rest salesforce


    【解决方案1】:

    这很可能是因为您的查询没有选择性并且需要很长时间才能运行。按照指示here 使您的查询具有选择性。简而言之,尽量不要在 where 子句中使用否定标准,如 或 NOT IN,并使用索引值。当您这样做时,查询将快速执行并且不会超时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 2018-11-14
      • 2022-09-23
      相关资源
      最近更新 更多