I'm passing a date/time field as a parameter to a page like this:
&startDate={!object.Start_date__c}
Start_date__c in object is a Date/Time field.
But when I open the link I get this error:
System.TypeException: Invalid date/time
In the page I'm linking with that parameter, which I can not modify for now, I can see that this is the line that generates the error:
DateTime startDate = DateTime.valueOf(startDateInputString);
How can I modify the parameter in input to make this work?
The problem seems to be that I'm passing 01-24-2013 1.00 with a blank space in my url.
Thanks
Best Answer
Here's what a DateTime looks like when blatted out on a page as a string:
(format one)
You can't just hydrate that string back into a DateTime. You must construct or deserialize it.
Here's what a serialized DateTime looks like:
(format two)
It's not the same as the above string output. You need something more like this:
And as a good web citizen, if you're serving up the parameter in a link it should be URL encoded:
And you might note that the
DateTime.valueOf
method expects yet a different value:(format three)
Knowing these, we can ensure that we are creating (and expecting) matching date formats.