如何在特定日期时间后过滤 Python 脚本中的 SOQL 查询?

How can I filter a SOQL query in a Python script after a specific datetime?

我正在尝试 select OPPORTUNITY 对象中大于变量 DateTime 的所有记录。但是,我无法弄清楚如何。这是在使用 simple_salesforce 包的 Python 脚本中。我认为问题要么是我从 BigQuery table 检索到的“max_date”参数中缺少毫秒和 +0000 时区规范,要么是我没有传递我的 max_date 参数作为正确的数据类型。

我的示例代码不起作用:

max_date = '2020-08-11T17:41:29'

SF_QUERY = ("""
  SELECT Id,
  CreatedDate
  FROM Opportunity
  WHERE CreatedDate > %s
  """ % max_date)

CreatedDate 字段的格式如下:

2019-10-31T16:01:19.000+0000

查询returns错误

 Response content: [{'message': "line 8:57 no viable alternative at character '<EOF>'", 'errorCode': 'MALFORMED_QUERY'}]

如果我在 %s 周围添加引号使其成为“%s”,则会出现错误

Response content: [{'message': "\n  AND BU_Last_Stage_Changed_Date__c >\n      ^\nERROR at Row:8:Column:7\nvalue of filter criterion for field 'BU_Last_Stage_Changed_Date__c' must be of type dateTime and should not be enclosed in quotes", 'errorCode': 'INVALID_FIELD'}]

感谢您的帮助。

参考文档:

解决方案是在我的日期时间字符串末尾附加一个“Z”(祖鲁时间的缩写),表示 UTC。动态变量 %s 不应有引号。示例:

max_date = '2020-08-10T17:41:29' # in prod, pull this data from BigQuery
max_date = max_date + "Z"

SF_QUERY = ("""
  SELECT Id,
  CreatedDate
  FROM Opportunity
  WHERE CreatedDate > %s
  """ % max_date)