I'm creating an application which has salesforce as backend and angularjs as front end. Salesforce Opportunity's closedate is a date type and when I serailaize it to json and get it in angularjs in UI it throws error so I have to create a new date instance in angular as

(new Date($scope.opp.CloseDate));

to accept date input for closedate in UI. so now closeDate for $scope.opp variable is a datetime value coming as '2016-06-28T00:00:00.000Z'. Now it all works fine on UI. But for saving it to backend in salesforce I’m deserializing json to opportunity object in vfremoting method like this:

oppty = (Opportunity)JSON.deserialize(opptyJson, Opportunity.class);

and getting this error 'Cannot deserialize instance of date from VALUE_STRING value 2016-06-28T00:00:00.000Z or request may be missing a required field'.

I have tried following till now:

  1. Tried to modify json string in angular controller before sending it to salesforce, but then again got issue on UI, that its not a valid date format. -> So, this approach doesn't work.

  2. Parsed json string in salesforce controller to get dateTime value, I’m getting '2016-06-28 00:00:00’. Created a jsonGenerator to write other opportunity fields and closedate after creating a new date instance to get correct salesforce supported date format. But now when I deserialize using above generated json string, I get this error: Visualforce Remoting Exception: Value does not match expected type.

I'm totally stuck now and unable to understand what could be the solution. I've also tried to find answer from existing questions but none seem to be working.

1 Answer 1


you can by this way new Date(selectedDate).toUTCString() on save

  • 1
    I'm getting error on deserialization of json to opportunity, before coming to save part itself. So, I think this would not work.
    – SfdcNovice
    Commented Jul 30, 2016 at 19:28

You must log in to answer this question.

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