You need to sign in to do that
Don't have an account?
kajal rathod
Create Custom object Records Using Lightning Component
Hi ,
I just sarted learning lightning and i am trying to insert data in my custom object from client side to server side but i m not able to .I try to debug also but it is showing value as undefined .
component----
<aura:component controller='TraningDetailsServer'>
<aura:attribute name='TraningDetails' Type='List' default="{ 'sobjectType': 'TraningDetails__c',
'Name': ' ',
'Employee ID': ' ',
}"/>
<lightning:input name="TraningDetails" label="Name" value='{!v.TraningDetails.Name__c}'/>
<lightning:input name="TraningDetails" label="Employee ID" value='{!v.TraningDetails.Emp_ID__c}'/>
<ui:button label="Submit"
class="slds-button slds-button--neutral"
labelClass="label"
press="{!c.getDetails}"/>
</aura:component>
controller---
({
getDetails : function(component, event, helper) {
var DetailsCmp=component.get("v.TraningDetails");
//var item = JSON.parse(JSON.stringify(DetailsCmp));
var action=component.get("c.TraningDetailsServer");
console.log(DetailsCmp);
var i;
for(i in DetailsCmp)
action.setParams({
"xyz": JSON.stringify(DetailsCmp[i].Name)
});
action.setCallback(this, function(a) {
var state = a.getState();
console.log(state);
if (state === "SUCCESS") {
var DetailsCall = a.getReturnValue();
alert("hello from here"+DetailsCall.Name);
}
});
$A.enqueueAction(action)
}
})
Apex class---
public with sharing class TraningDetailsServer {
@AuraEnabled
public static List<TraningDetails__c> TraningDetailsServer(List<TraningDetails__c> xyz)
{
insert xyz;
return xyz;
}
}
can some body help me with what is wrong in my code
I just sarted learning lightning and i am trying to insert data in my custom object from client side to server side but i m not able to .I try to debug also but it is showing value as undefined .
component----
<aura:component controller='TraningDetailsServer'>
<aura:attribute name='TraningDetails' Type='List' default="{ 'sobjectType': 'TraningDetails__c',
'Name': ' ',
'Employee ID': ' ',
}"/>
<lightning:input name="TraningDetails" label="Name" value='{!v.TraningDetails.Name__c}'/>
<lightning:input name="TraningDetails" label="Employee ID" value='{!v.TraningDetails.Emp_ID__c}'/>
<ui:button label="Submit"
class="slds-button slds-button--neutral"
labelClass="label"
press="{!c.getDetails}"/>
</aura:component>
controller---
({
getDetails : function(component, event, helper) {
var DetailsCmp=component.get("v.TraningDetails");
//var item = JSON.parse(JSON.stringify(DetailsCmp));
var action=component.get("c.TraningDetailsServer");
console.log(DetailsCmp);
var i;
for(i in DetailsCmp)
action.setParams({
"xyz": JSON.stringify(DetailsCmp[i].Name)
});
action.setCallback(this, function(a) {
var state = a.getState();
console.log(state);
if (state === "SUCCESS") {
var DetailsCall = a.getReturnValue();
alert("hello from here"+DetailsCall.Name);
}
});
$A.enqueueAction(action)
}
})
Apex class---
public with sharing class TraningDetailsServer {
@AuraEnabled
public static List<TraningDetails__c> TraningDetailsServer(List<TraningDetails__c> xyz)
{
insert xyz;
return xyz;
}
}
can some body help me with what is wrong in my code
As per image, your code is executed and it is successful. As you are returning List, please try to iterate and then check DetailsCall.Name with record index.