1

I have a @restResource that's receiving a JSON payload as a string. I am taking that payload and placing it into a Map<String, Object> variable. I'm trying to save the date/time into a variable that I can later pass to Salesforce.

String raw_start_date = (String)response.get('start_date');

Datetime start_date = Datetime.parse(raw_start_date);

I keep getting the following error when I receive my test packet:

FATAL_ERROR System.TypeException: Invalid date/time: 2020-01-15T00:00:00Z

What am I missing here? I'm I using the wrong command to get the data saved into a Datetime variable?

0

1 Answer 1

1

This post is asking a similar question.

To quote from that answer:

'To parse DateTimes in ISO format, you need to use JSON deserialization. The JSON parser understands ISO format, while DateTime.parse() uses the running user's locale settings.'

You'll want to use something like:

Datetime dt = (DateTime)JSON.deserialize('"' + raw_start_date + '"', DateTime.class);

1
  • 1
    I tried that exact example an hour ago and it didn't work. For whatever reason it works now. Not even going to question it. Thank you
    – Richard
    Dec 19, 2019 at 23:41

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