You need to sign in to do that
Don't have an account?
Eldon
Create record from a lightning component
Hi,
We were trying to get input from user through submit form in a lightning component and with that input values create a record in a custom object. We got the input by the following code:
<aura:attribute name="custDetail" type="CustomerDetail__c[]"></aura:attribute>
<aura:attribute name="customerInfo" type="CustomerDetail__c" default="{ sobjectType: 'CustomerDetail__c' }" />
<force:inputField value="{!v.customerInfo.Name}"/>
<ui:button label="Edit Record" press="{!c.saveDetails}"/>
Our jscontroller looks like the following
({
saveDetails : function(component, event, helper)
{
var dets = component.get("v.customerInfo.Name");
alert(dets);
//console.log('dets::' + dets);
//debugger;
helper.save(component,dets);
}
})
We get the name in the alert correctly when we submit.
Next the helper is as following
({
save: function(component, dets) {
//Save the expense and update the view
this.upsertDet(component, dets, function(a) {
var dets3 = component.get("v.custDetail");
dets3.push(a.getReturnValue());
console.log('here'+dets3);
component.set("v.custDetail", dets3);
});
},
upsertDet : function(component, dets, callback) {
var action = component.get("c.saveDetailsGiven");
action.setParams({
"dets": dets
});
if (callback) {
action.setCallback(this, callback);
}
$A.enqueueAction(action);
}
})
Apex class::
public class saveCusDetails {
@AuraEnabled
public static string saveDetailsGiven(CustomerDetail__c details) {
upsert details;
system.debug('#####'+ details);
return details.Id;
}
}
There are no errors but the record is not getting created. Any help would be appreciated.
Thank you
We were trying to get input from user through submit form in a lightning component and with that input values create a record in a custom object. We got the input by the following code:
<aura:attribute name="custDetail" type="CustomerDetail__c[]"></aura:attribute>
<aura:attribute name="customerInfo" type="CustomerDetail__c" default="{ sobjectType: 'CustomerDetail__c' }" />
<force:inputField value="{!v.customerInfo.Name}"/>
<ui:button label="Edit Record" press="{!c.saveDetails}"/>
Our jscontroller looks like the following
({
saveDetails : function(component, event, helper)
{
var dets = component.get("v.customerInfo.Name");
alert(dets);
//console.log('dets::' + dets);
//debugger;
helper.save(component,dets);
}
})
We get the name in the alert correctly when we submit.
Next the helper is as following
({
save: function(component, dets) {
//Save the expense and update the view
this.upsertDet(component, dets, function(a) {
var dets3 = component.get("v.custDetail");
dets3.push(a.getReturnValue());
console.log('here'+dets3);
component.set("v.custDetail", dets3);
});
},
upsertDet : function(component, dets, callback) {
var action = component.get("c.saveDetailsGiven");
action.setParams({
"dets": dets
});
if (callback) {
action.setCallback(this, callback);
}
$A.enqueueAction(action);
}
})
Apex class::
public class saveCusDetails {
@AuraEnabled
public static string saveDetailsGiven(CustomerDetail__c details) {
upsert details;
system.debug('#####'+ details);
return details.Id;
}
}
There are no errors but the record is not getting created. Any help would be appreciated.
Thank you
https://github.com/fracarma/Lightning-Object-Creator-Component
Thanks
http://www.salesforceadda.com/2017/09/create-and-display-account-records.html