我正在尝试使用日期时间查询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的格式错误的查询错误。 有人可以帮忙吗?
答案 0 :(得分: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)
答案 1 :(得分: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=This%20function%20is%20exactly%20opposite,datetime%20object%20to%20a%20string.&text=Here%20the%20function%20returns%20struct_time,returned%20by%20ctime()%20function
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)