3

我正在尝试将 Salesforce 数据加载到 Python 数据框中,以便我们可以在那里进行所有操作。simple_salesforce 警告我们达到了 2,000 个限制:

from simple_salesforce import Salesforce as s
eatpies = sf.query('Select Id from Case')
attrs = ['Id']
records = eatpies['records']

data = {}

for rec in records:
    for k in attrs:
        data.setdefault(k, []).append(rec[k])

dframe = pd.DataFrame(data)

print(dframe)

据说,salesforce-bulk ( https://pypi.python.org/pypi/salesforce-bulk/1.0.7 ) 能够绕过这个限制,但我不能比这更进一步:

job = bulk.create_query_job("Case", contentType='CSV')
batch = bulk.query('select Id, type from Case')

TypeError                                 Traceback (most recent call last)
<ipython-input-13-076e14bf245d> in <module>()
----> 1 batch = bulk.query('select Id, type from Case')

TypeError: query() missing 1 required positional argument: 'soql'

请帮忙,谢谢!如果解决方案可以在 simple-Salesforce 中完成以克服 Salesforce 限制,那就太好了,但我无法通过 Google 找到任何解决方案。

4

2 回答 2

4

换行

eatpies = sf.query('Select Id from Case')

到以下:

eatpies = sf.query_all('Select Id from Case')

方法 query_all 是一个方便的包装器query(...)query_more(...)

从文档:

如果由于结果特别大,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)

您还可以通过 simple-salesforce 访问 Bulk API。例如,替换

eatpies = sf.query('Select Id from Case')
attrs = ['Id']
records = eatpies['records']

具有以下内容:

eatpies = sf.bulk.Case.query('Select Id from Case')
attrs = ['Id']
records = eatpies

有关使用批量 API 的更多信息:https ://github.com/simple-salesforce/simple-salesforce#using-bulk

于 2017-10-16T14:11:42.057 回答
1
sf.query_all("select count(Id) from visitors where CreatedDate >= 2017-12-01T00:00:00.000+0000 and CreatedDate < 2019-01-01T00:00:00.000+0000", True)
于 2019-02-10T18:52:44.880 回答