无法使用Python从Salesforce获取完整记录 [英] Unable to fetch complete records from Salesforce using Python

查看:80
本文介绍了无法使用Python从Salesforce获取完整记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python中的 simple_salesforce 库从salesforce提取数据.

I am trying to fetch the data from salesforce using the simple_salesforce library in python.

运行计数查询时,我能够获得正确的记录计数.

I am able to get the correct count of records while running the count query.

但是,当我尝试将结果(以列表的形式)作为JSON对象放入s3时,持久存留的记录并没有像我从Salesforce捕获的记录那样多.

But while I am trying to put that results (in the form of list) into s3 as a JSON object, not as many reocrds are getting persisted as I captured from Salesforce.

这是代码段:

result = sf.query("SELECT ID FROM Opportunity")['records']
object.put(Body=(bytes(json.dumps(result, indent=2).encode('UTF-8'))))

是Salesforce方面的问题,还是我使用AWS的SDK将对象放入S3时遇到了问题?

Is the problem on the Salesforce side or am I running into an issue using AWS's SDK to put the objects into S3?

推荐答案

Salesforce API会分块返回内容,默认一次是2000条记录.如果返回给您1M记录,则可能会杀死您的内存使用量.检索一个块,进行处理(保存到文件?),请求下一个块.

Salesforce API returns stuff in chunks, default is 2000 records at a time. If it'd return to you 1M records it could kill your memory usage. Retrieve a chunk, process it (save to file?), request next chunk.

直接在项目主页:

如果由于特别大的结果,Salesforce添加了一个查询结果的nextRecordsUrl,例如"nextRecordsUrl":"/services/data/v26.0/query/01gD0000002HU6KIAW-2000",您可以拉ID或完整网址的其他结果(如果使用完整网址,您必须将"True"作为第二个参数)

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)

为方便起见,在单个本地中检索所有结果方法调用使用

As a convenience, to retrieve all of the results in a single local method call use

sf.query_all("SELECT Id, Email FROM Contact WHERE LastName = 'Jones'")

这篇关于无法使用Python从Salesforce获取完整记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆