function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Christian Szandor KnappChristian Szandor Knapp 

Aura Attribute of Type Date - issues with DML On Apex Controller Side

Hey all,

I am experiencing an issue with aura attributes of the type date.

So we got a comoponent with an aura attribute
<aura:attribute name="dateToday" type="Date"/>

We got a Apex Controller with a  method like this one
@auraEnabled
public static insertDate(Date myDate){

//some code that sets the date on sObject.datefield

insert sOBject;

}

Mind you:
the js controller sends myDate to the Apex Controller (set etc)
The Apex Controller requires Date type as parameter
The Apex Controller accepts myDate as Type Date for the method
But DML fails: incorrect format, the myDate in ApexController misses the time part the dml statement seems to require (2015-11-05 00:00:00 instead of 2015-11-05 only)

is this per chance a known issue?

Kind Regards,
Sz
James LoghryJames Loghry
Passing dates back and forth from components and Apex is rather tricky.  Have you verified the format of myDate via System.debug statements?

I would suggest trying the following:
 
myDate = Date.parse(myDate.format());
Christian Szandor KnappChristian Szandor Knapp
Hey James,

yes, on apex controller side I did. The format was like any other date would show in system.debug. 

On another note, I used on client controller side: 
 
var date = $A.localizationService.parseDateTime(component.get("v.date"););
- which worked charmingly well for Chrome. 

I did not work on iOS (iPhone 6) or Firefox: Had to drop a feature alltogether (prefil aura inputdate field with today()+7 for convenience) since the behaviour was rather erratic. It behaves like Aura was affected by the depracated warning showing up when running above code: https://github.com/moment/moment/issues/1407

Very frustrating alltogether, but again - I am not an expert in Clientside Javascript. 

Regards,
Sz