I'm trying below example which is giving ERROR as response. Any idea on how to get the below code execution successfully:
Component:
<aura:component controller="ConCreation">
<aura:attribute name="conInfo" type="Contact" default="{'sObject':'conatct','LastName':''}"/>
<ui:inputText aura:id="LastName" label="Last Name"
value="{!v.conInfo.LastName}"
required="true"/>
<ui:inputText aura:id="FirstName" label="First Name"
value="{!v.conInfo.FirstName}"
required="true"/>
<ui:button press="{!c.saveCon}" label="click"/>
</aura:component>
Aura controller:
({
saveCon : function(component, event) {
var con = component.get("v.conInfo");
var action1 = component.get("c.saveContact");
action1.setParams({
"c": con
});
action1.setCallback(this, function(response) {
var state = response.getState();
console.log('state--'+state);
if (component.isValid() && state === "SUCCESS") {
component.set("v.conInfo", response.getReturnValue());
}
});
$A.enqueueAction(action1);
}
})
Aura apex Class:
global with sharing class ConCreation{
@auraenabled
public static string saveContact(contact c){
if(c != null)
{
insert c;
system.debug('c--'+c);
}
return c.id;
}
}