ApexSystem.TypeException: Invalid date/time: 2021-12-28T09:20:46-05:00

System.TypeException: Invalid date/time: 2021-12-28T09:20:46-05:00

To parse DateTimes in this ISO format, you need to use JSON deserialization.

String dateStr = '2021-12-28T09:20:46-05:00';
Datetime dateTime = (DateTime)JSON.deserialize('"' + dateStr+'"', DateTime.class);

The JSON parser understands ISO format, while DateTime.parse() uses the running user’s locale settings.

- Advertisement -spot_img

More From UrbanEdge

Top Salesforce Static Code Analysis Tools: Enhancing Code Quality and Security

#Heading1Introduction2What is Salesforce?3The Importance of Code Analysis4Understanding Static Code...

Trigger Challenge #12: Understanding the Trigger on Account and its Impact on Salesforce Development

As a Salesforce developer, understanding how triggers work is...

Best Practices for Apex Triggers

Introduction Apex Triggers are a fundamental aspect of Salesforce development,...

Why LWC was introduced?

Salesforce LWC: The Best Way to Create Customized User...
- Advertisement -spot_img