Passing Date in format [YYYY-M-D] like "2016-1-1" gives error "Unable to read SObject's field value[s]"
Steps to reproduce:
Create custom object Custom_Object__c with Date field Date__c
Create Apex Class
public class DateIssueCont { @AuraEnabled public static void saveRecord( Custom_Object__c rec ){ insert rec; } }
Create an App
<aura:application controller="DateIssueCont"> <aura:attribute name="record" type="Custom_Object__c" default="{'sobjectType': 'Custom_Object__c', 'Date__c': ''}" /> <ui:inputDate value="{!v.record.Date__c}" displayDatePicker="true" /> <aura:handler name="init" value="{!this}" action="{!c.init}"/> <div aura:id="errors" class="slds-hide"> <div class="slds-form-element" > <div class="slds-form-element__control"> <ui:message title="Error" severity="error" > <ui:outputText aura:id="ErrorMessage" value=""/> </ui:message> </div> </div> </div> <button class="slds-button slds-button--neutral slds-button--brand" onclick="{!c.perform}">Perform Business Logic</button> </aura:application>
With Javascript Controller
({ init : function(component, event, helper) { component.set("v.record.Date__c", '2016-1-1' ); }, perform : function(component, event, helper) { var rec = component.get( 'v.record' ); var saveRecord = component.get( "c.saveRecord" ); saveRecord.setParam( "rec", rec ); saveRecord.setCallback(this, function(response) { var state = response.getState(); if (component.isValid() && state === "SUCCESS") { } else if (state === "ERROR"){ var errors = response.getError(); if (errors && errors[0] && errors[0].message) { $A.util.removeClass( component.find("errors"), "slds-hide"); component.find("ErrorMessage").set("v.value", errors[0].message); } if (errors && errors[0] && errors[0].pageErrors && errors[0].pageErrors[0] && errors[0].pageErrors[0].message ) { $A.util.removeClass( component.find("errors"), "slds-hide"); component.find("ErrorMessage").set("v.value", errors[0].pageErrors[0].message); } if (errors && errors[0] && errors[0].fieldErrors ) { $A.util.removeClass( component.find("errors"), "slds-hide"); for ( var u in errors[0].fieldErrors) { component.find("ErrorMessage").set("v.value", errors[0].fieldErrors[u][0].message); } } } }); $A.enqueueAction(saveRecord); } })
Open an app and click button.
Obtain an error which says "Unable to read SObject's field value[s]".