gpt4 book ai didi

python - 将 Salesforce 数据转换为 Python(simple-Salesforce 或 salesforce-bulk)

转载 作者:太空宇宙 更新时间:2023-11-04 00:28:42 27 4
gpt4 key购买 nike

我正在尝试将 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'

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

最佳答案

换行

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

以下内容:

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

query_all 方法是 query(...)query_more(...) 的便捷包装器。

来自文档:

If, due to an especially large result, Salesforce adds a nextRecordsUrl to your query result, such as "nextRecordsUrl" : "/services/data/v26.0/query/01gD0000002HU6KIAW-2000", you can pull the additional results with either the ID or the full URL (if using the full URL, you must pass 'True' as your second argument)

sf.query_more("01gD0000002HU6KIAW-2000")
sf.query_more("/services/data/v26.0/query/01gD0000002HU6KIAW-2000", True)

您还可以通过 simple-salesforce 访问批量 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

关于python - 将 Salesforce 数据转换为 Python(simple-Salesforce 或 salesforce-bulk),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46551314/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com