function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eric Blaxton 11Eric Blaxton 11 

Deserialize JSON String Date to DateTime

Hi and thanks in advance.
My goal is to speed up an area of my apex class.  I was told that deserializing in a loop causes drag.  

I can successfully deserialize a JSON string Date to a DateTime value like this:
reportDate= (DateTime)JSON.deserialize('"' + valueMap.get('reportDate') + '"', DateTime.class);
I tried using DateTime.valueof like this:
reportDate= datetime.valueof(valueMap.get('reportDate'));
Here's the error I get:
Line: 74, Column: 1
System.TypeException: Invalid date/time: 2020-12-28T11:33:31-06:00

Eric



 
ShirishaShirisha (Salesforce Developers) 
Hi Eric,

Greetings!

Please refer this for more information related to this error.

https://salesforce.stackexchange.com/questions/247210/system-typeexception-invalid-date-time-2019-01-03t002601-711-0200

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri