Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm officially breaking up with Salesforce Date parsing. This has got to be the most frustrating thing.

I have the following date in a JSON string (full JSON below):

2017-06-03T10:34:24.000Z

But when I try to deserialize the data:

Opportunity[] results = (List<Opportunity>)JSON.deserialize(res, List<Opportunity>.class);

I get the following error:

System.JSONException: Cannot deserialize instance of date from VALUE_STRING value 2016-12-05T16:19:44.000Z

I have looked at so many date parse issues before and from what I've gathered it must be in ISO 8601 - though ISO 8601 can take various shapes: Ruby Docs: ISO 8601

All of the following seem to recommend exactly what I've done

Cannot deserialize instance of datetime from VALUE_STRING value

https://developer.salesforce.com/forums/?id=906F00000009BsqIAE

https://github.com/heroku/databasedotcom/issues/22

https://github.com/heroku/databasedotcom/issues/35

How should I format this date string?

Thank you!

Full JSON string:

[{
  "name":"OpportunityABC",
  "CloseDate":"2017-06-03T10:34:24.000Z",
  "StageName":"Pre-Engagement",
  "Amount":"4810308.0",
}]
share|improve this question
up vote 13 down vote accepted

Three problems here:

(a) Date receiving DateTime value.

The value should be "YYYY-MM-DD" only.

(b) Decimal receiving String value.

The value should not be in quotes.

(c) You must not have a trailing comma.

JSON-compliant strings are more strict than normal JavaScript.

[{
  "name":"OpportunityABC",
  "CloseDate":"2017-06-03",
  "StageName":"Pre-Engagement",
  "Amount":4810308.0
}]
share|improve this answer
    
Making the change to Date instead of DateTime fixed it. Thanks man! – ZAR Mar 30 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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