0

我正在尝试使用日期时间查询 sfdc,我尝试使用日期作为字符串,然后作为日期时间对象,但是我得到格式错误的查询,因为这样使用它

dateTime = sys.argv[1] 

result = sf.query("select Case__r.CaseNumber from File_Attachment__c where ( LastModifiedDate >= dateTime) ")

我也试过

from dateutil.parser import parse dtime = parse(dateTime)

result = sf.query("select Case__r.CaseNumber from File_Attachment__c where ( LastModifiedDate >= dtime) ")

result = sf.query("select Case__r.CaseNumber from File_Attachment__c where ( LastModifiedDate >= :dtime) ")

但都给了我来自 sfdc 的格式错误的查询错误。任何人都可以帮忙吗?

4

2 回答 2

0

日期时间的 SFDC 链接- https://help.salesforce.com/articleView?id=000325035&type=1&mode=1日期时间 的 Python 链接- https://www.journaldev.com/23365/python-string-to-datetime-strptime #:~:text=Python%20strptime(),-Python%20strptime()&text=这个%20function%20is%20exactly%20opposite,datetime%20object%20to%20a%20string.&text=这里%20the%20function%20returns% 20struct_time,返回%20by%20ctime()%20函数

from simple_salesforce import Salesforce
sf = Salesforce(
username='XXX', 
password='XXX', 
security_token='XXX')
result = sf.query("SELECT Id, Email FROM Contact WHERE LastName = 'Jones'")
print(result)

单击链接以查看 python 代码图像及其结果

于 2021-01-16T19:01:49.290 回答
0

使用 beatbox 和 python 2.7 以下代码执行成功的查询。要么您使用的是不同的 python 版本,要么日期格式不正确,要么查询参数不正确(Case__r.CaseNumber 或 File_Attachment__c)

import beatbox

"salesforceusername and password"
username = 'xxx'
password = "xxx"
token    = 'xxx'

"""conenct and authenticate"""
svc = beatbox.PythonClient()
svc.login(username, password+token)

"""execut SOQL query"""
res = svc.query("select ID from Case where LastModifiedDate >= 2005-05-18T14:01:00-04:00")

"""prints results in console"""
print(res)
于 2016-05-19T05:49:41.873 回答