简体   繁体   中英

SOQL query in SFDC using simple salesforce (python)

I am trying to query sfdc using a datetime, I tried using the date as a string, then as a datetime object, but I get malformed query for using it like this

dateTime = sys.argv[1] 

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

I also tried

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

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

and

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

but all give me malformed query error from sfdc. Can anyone help?

using beatbox and python 2.7 the following code executes a successful query. Either you are using a different python version, the date format is incorrect or the query parameters are incorrect (Case__r.CaseNumber Or 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM