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)
SFDC link for Datetime - https://help.salesforce.com/articleView?id=000325035&type=1&mode=1 Python link for Datetime - 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)
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.