本文介绍了Simple_Salesforce:在日期范围内进行批量 SQL 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Simple_Salesforce 通过 salesforce api 获取大量数据.我想知道是否可以在拨打电话时指定日期范围.我不断收到以下错误.

I'm using Simple_Salesforce to grab a chunk of data using the salesforce api. I was wondering if there was anyway to specify a date range when making calls. I keep getting the following error.

query = 'SELECT Id, Name FROM Account WHERE createddate > 1451621381000'

sf.bulk.Account.query(query)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/simple_salesforce/bulk.py", line 157, in _get_batch_results
    url_query_results = "{}{}{}".format(url, '/', result.json()[0])
IndexError: list index out of range

query = 'SELECT Id, Name FROM Account WHERE createddate > 2017-01-01'

这有效,所以我可以过滤条件

This works, so I can filter on conditions

query = "SELECT Id, CreatedDate FROM Tbl WHERE Id = '500G0000008LeHzIAK'"
dd = sf.bulk.Tbl.query(query)
df = pd.DataFrame(dd)

然而,日期似乎以一种奇怪的方式保存,这会引发错误

However, date seems to be saved in an odd manner and this throws an error

query = "SELECT Id, CreatedDate FROM Case Tbl CreatedDate = '1328828872000L'"
query = "SELECT Id, CreatedDate FROM Case Tbl CreatedDate > '1328828872000L'"
dd = sf.bulk.Tbl.query(query)
df = pd.DataFrame(dd)

日期值如下所示:1463621383000L

推荐答案

Datetime fields(例如 CreatedDate)只能通过日期时间格式的值过滤,有或没有时区偏移,全部不带引号.(详细了解 SOQL 日期格式)

Datetime fields (e.g. CreatedDate) can be filtered only by values in Datetime format, with or without timezone offset, all without quotes. (read more about SOQL Date Formats)

SELECT Id FROM Case WHERE CreatedDate > 2017-01-31T23:59:59Z

日期字段只能按日期格式

SELECT Id FROM Opportunity WHERE CloseDate > 2017-01-31

如果您对创建的记录感兴趣,例如在最后一分钟,您可以通过以下方式构建价值:

If you are interested in records created e.g. in the last minute, you can build the value by:

sf_timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(time.time() - 60))
sql = "SELECT Id FROM Account WHERE CreatedDate > %s" % sf_timestamp

我看到您的数字时间戳以毫秒为单位,因此您必须先将其除以 1000.

I see that your numeric timestamp is in miliseconds, therefore you must divide it by 1000 first.

我不相信你的例子 createddate >2017-01-01 对你有用,因为它不应该根据参考工作.您收到一条错误消息:

I don't believe that your example createddate > 2017-01-01 works for you because it shouldn't work according the reference. You get an error message:

错误:字段 'createddate' 的过滤条件值必须是 dateTime 类型,不应用引号括起来

Simple Salesforce 似乎没有正确报告来自 Salesforce 的原始错误消息,Simple-Salesforce 最终只报告了后续错误.(所有示例都经过验证,但不是通过 simple-salesforce.)

It seems that Simple Salesforce doesn't report correctly the original error message from Salesforce and only subsequent errors are eventually reported by Simple-Salesforce. (All examples verified, but not by simple-salesforce.)

这篇关于Simple_Salesforce:在日期范围内进行批量 SQL 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:25