You need to sign in to do that
Don't have an account?

@RemoteAction and Date arguments from javascript
The documentation for javascript remoting says, "Your method can take Apex primitives as arguments," and I'd like to pass a Javascript Date into my remoted function. Javascript Date has a time component, so it's analogous to an Apex DateTime.
However, when I pass in the Date from javascript calling my remoted function, the remoting javascript code throws an exception complaining that I'm not passing in a DateTime but rather the time as an ISO string.
I noticed that in the opposite direction, DateTimes get marshaled as an integer of the number of milliseconds since the epoch (Jan 1, 1970), which javascript can use in a Date constructor, so I tried passing that in for the DateTime arg, but it still complained.
Is there a way to pass a Javascript Date directly to a remoted function as an Apex DateTime??
My workaround in the meantime was to accept the Date as an ISO string, replace the "T" with a space, and use the result to construct the Apex DateTime with DateTime.valueOf. It'd be nice to be able to skip this, though.
Thanks,
--Kevin
Hey Kevin.
Try passing the result of Date.toUTCString() to the client-side remote method.
All Answers
Hey Kevin.
Try passing the result of Date.toUTCString() to the client-side remote method.
Awesome - this seems to do the trick.
Is this in the docs somewhere, and I missed it?
Gracias!
I also want the same result for my requirement Can you please post the sample code for that