I am using salesforce REST API to retrieve all the accounts. Something like this:


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 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 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?

2 Answers 2


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:

lastmodifiedDate > 2017-04-03T20:12:37.000 0000
                                          ^ + character got converted to space

Also, if you are terminating your query string with a semicolon (;), remove that.

This WHERE clause URI should work:


Thank you for your response. I had to encode '>' as well. So the final query that works is

  • 1
    Interesting, I didn't have to encode > in workbench.
    – Adrian Larson
    Commented May 2, 2017 at 16:30
  • A note on Stack Exchange mechanics: If the above answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Commented May 2, 2017 at 16:30
  • I wanted to accept it as the correct answer, but for some very odd reason I do not see a Check mark to the left. Hence I up-voted it! Commented May 2, 2017 at 20:25
  • You've logged in via separate accounts. You should be able to merge them via the contact us link.
    – Adrian Larson
    Commented May 2, 2017 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .