I am using salesforce REST API to retrieve all the accounts. Something like this:
..."/query?q=select+name,+cust_number__c,+cust_status__c+from+account+where+cust_number__c+!=null"
I need to retrieve the delta records once a day. So I am planning to use 'lastmodifiedDate'. Retrieve any record where the lastmodifiedDate is greater than my last pull. But I am getting an error
.../query?q=select+name,+CreatedDate+,+lastmodifiedDate,+cust_number__c,+cust_status__c+from+account+where+lastmodifiedDate+%3e+2017-04-03T20:12:37.000+0000;
Query was unsuccessful. Status code returned is 400
An error has occured. Http status: 400[ { "message" : "\nlastmodifiedDate > 2017-04-03T20:12:37.000 0000\n ^\nERROR at Row:1:Column:159\nline 1:159 no viable alternative at character ' '", "errorCode" : "MALFORMED_QUERY" } ]
when I try this query:
.../query?q=select+name,+CreatedDate+,+lastmodifiedDate,+cust_number__c,+cust_status__c+from+account+where+lastmodifiedDate+>+2017-04-03T20:12:37.000+0000;
Query URL: Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 190:
Exception for '>'
How can I get results with date in the where clause?
Best Answer
You need to encode the plus sign (
+
) in your timezone offset (to%2B
). Instead of.000+0000
, use.000%2B0000
. If you use a plus character (+
) it will get converted to a space (). Notice your error message clause:
Also, if you are terminating your query string with a semicolon (
;
), remove that.This
WHERE
clause URI should work: