1

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?

1

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:

WHERE+LastModifiedDate>2017-04-03T20:12:37.000%2B0000
| improve this answer | |
0

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

.../query?q=select+name,+CreatedDate+,+lastmodifiedDate,+cust_number__c,+cust_status__c+from+account+where+lastmodifiedDate+%3e+2017-04-03T20:12:37.000%2B0000
| improve this answer | |
  • Interesting, I didn't have to encode > in workbench. – Adrian Larson May 2 '17 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 May 2 '17 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! – user1860447 May 2 '17 at 20:25
  • You've logged in via separate accounts. You should be able to merge them via the contact us link. – Adrian Larson May 2 '17 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.