Using JS Remote Objects, I'm trying to INSERT a record that has a date field as a required field (an Opportunity). I am getting this value from a user input, which I'm using JQuery.validate to validate that it is in date format. The string can look like either:

12/12/2016 or 2016/12/12

This was rejected as an invalid type. Looking at how to format strings in the SF API docs:

To insert record into Date or Date Time field using Data Loader:

1) "Date" type field accept either one of below format:


yyyy-mm-dd hh:mm:ss



I tried inputting the date as 2016-12-12, still didn't work.

How can I, in JS, supply a value that the API will accept?

BTW, I'm just using the basic create JS Remote Object method:

   name:      'oppName',
   CloseDate: '2016-12-12',
   StageName: 'Engagement'

1 Answer 1


You can pass javascript date object to the apex date field..

initialise the js date from the date string and pass the js date variable

var dt = new Date('2015-12-12');
var oppDetails = { Name: 'Test Opp', CloseDate: dt, StageName:'New' };

here's the full code I tested in my dev org which worked..

<apex:page >
  <script type="text/javascript">
     function createOpp(){    
        var dt = new Date('2015-12-12');
        var oppDetails = { Name: 'Test Opp', CloseDate: dt, StageName:'New' };
        var opp = new RemoteObjectModel.Opportunity();
        opp.create(oppDetails, function(err) {
            if(err) { 
            else {
  <apex:remoteObjects jsNamespace="RemoteObjectModel">
    <apex:remoteObjectModel name="Opportunity" fields="Id,Name,CloseDate,StageName">
  <input type="button" onClick="createOpp()" value="Create Opp" />
  • What if you wanted to nullify the date value, what would you need to pass as a value for date or datetime fields?
    – rcraven
    Dec 30, 2015 at 1:00
  • @rcraven have you tried null? Jan 14, 2016 at 18:56
  • What is the datatype of CloseDate? Date or Datetime? Sep 18, 2018 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.