您希望使用 salesforce_connection.query(query=SOQL) 然后 .query_more(nextRecordsUrl, True)
由于 .query() 只返回 2000 条记录,您需要使用 .query_more 来获取下一页结果
来自simple-salesforce 文档
SOQL 查询通过以下方式完成:
sf.query("SELECT Id, Email FROM Contact WHERE LastName = 'Jones'")
如果由于结果特别大,Salesforce 将nextRecordsUrl添加到您的查询结果中,例如"nextRecordsUrl" : "/services/data/v26.0/query/01gD0000002HU6KIAW-2000",您可以使用ID 或完整的 URL (如果使用完整的 URL,你必须传递 'True' 作为你的第二个参数)
sf.query_more("01gD0000002HU6KIAW-2000")
sf.query_more("/services/data/v26.0/query/01gD0000002HU6KIAW-2000", True)
这是一个使用这个的例子
data = [] # list to hold all the records
SOQL = "SELECT my_field FROM my_model"
results = sf.query(query=SOQL) # api call
## loop through the results and add the records
for rec in results['records']:
rec.pop('attributes', None) # remove extra data
data.append(rec) # add the record to the list
## check the 'done' attrubite in the response to see if there are more records
## While 'done' == False (more records to fetch) get the next page of records
while(results['done'] == False):
## attribute 'nextRecordsUrl' holds the url to the next page of records
results = sf.query_more(results['nextRecordsUrl', True])
## repeat the loop of adding the records
for rec in results['records']:
rec.pop('attributes', None)
data.append(rec)
遍历记录并使用数据
## loop through the records and get their attribute values
for rec in data:
# the attribute name will always be the same as the salesforce api name for that value
print(rec['my_field'])
就像其他答案所说的那样,这可能会开始消耗大量资源。但是,如果要实现页面国家,您正在寻找什么。
也许创建一个更集中的 SOQL 语句来仅获取您的用例在特定时刻所需的记录。