I am trying to pass a variable into SOQL statement, I am using simple_salesforce library. I only need to grab the data when CreateDate of the Opportunity is > than yesterday, yesterday's date is saved in last_run_day
variable. Below is my code:
yesterday = date.today() + timedelta(days=-1)
last_run_date = yesterday.strftime("%Y-%m-%d"+"T"+"%H:%M:%S"+"Z")
sf_data = sf.query_all("SELECT ID, Name FROM Opportunity where probability > 0 AND CreatedDate > '%s' AND AdPoint_Id__c <> NULL ORDER BY AdPoint_Id__c" % last_run_date)
print(sf_data)
Gives me an error: field 'CreatedDate' must be of type dateTime and should not be enclosed in quotes", 'errorCode': 'INVALID_FIELD'
%s
otherwise the date will be considered as String, which is not correct OR simply writewhere CreatedDate > YESTERDAY
. See date literals here developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/… – manjit5190 Apr 4 '20 at 19:55%
formatting. – David Reed♦ Apr 4 '20 at 20:20