I have a custom salesforce object with a Date field. I am creating a new object of this type in a Lightning component, and trying to push this to the server.

The objects are stored in a component attribute:

<aura:attribute name="objectsToInsert" type="Object__c[]"/>

Which is acted on by the controller method:

cmp.set("v.objectsToInsert", objectsToInsert);
helper.insertObjects(cmp, cmp.get("v.objectsToInsert")); 

When the attribute is set, the date field has already been set. It is set as a string in the format "YYYY-MM-DD" as shown below.

helper.insertObjects() includes:

var insertAction = cmp.get("c.insertObjects");
insertAction.setParam("objects", objects);      
console.log("entries: " + JSON.stringify(objects));

The log statement there shows a date field


Outputting the passed objects in the controller like this

public static void insertObjects(List<Object__c> objects) {

The debug statement here shows the field as


I have tried looking at other answers that were getting errors with Date fields, but can't find any solution or other examples of where the value just gets nulled. How do I fix this?

UPDATE ON SOLUTIONS: The accepted answer below describes a very simple workaround which will probably be sufficient. For others who would rather not use this method, the field containing the Date (Day__c) comes out of the serialiser with a value of Day__c=2016-12-09 00:00:00, i.e. it has a (zero'd out) time string, which may be necessary for apex to understand the data coming from Lightning.

  • Can you add your component code showing your attributes and client side JavaScript controller Commented Dec 7, 2016 at 2:12
  • I've update the question with more detail, is this enough?
    – nicstella
    Commented Dec 7, 2016 at 2:37
  • I need more info on how you are setting date fields to investigate Commented Dec 7, 2016 at 10:12

2 Answers 2


Try this ;)

You have to pass function parameter value in String format then deserialize them;

public static void insertObjects(String objects) {
    List<Object__c> objList = (List<Object__c>) Json.deserialize(objects, List<Object__c>.class);

  • 1
    While this is a work around, it is extremely simple to implement and so I will accept it.
    – nicstella
    Commented Dec 8, 2016 at 20:40

This also works if you're dealing with typed parameters directly, i.e. if you have this in your Apex controller:

public static void MyMethodOfDoom(Date dayOfReckoning)
    if(System.today() == dayOfReckoning)
        delete [select Id from Contact];

And you're passing the data by creating a JavaScript date object:

let doom = new Date();

You're going to be getting null for dayOfReckoning.

Simply changing the Apex controller to take a String parameter so is enough (you can leave the JavaScript as is):

public static void MyMethodOfDoom(String dayOfReckoning)
    if(System.today() == Date.valueOf(dayOfReckoning))
        delete [select Id from Contact];

You must log in to answer this question.

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