You need to sign in to do that
Don't have an account?
Debasish Paul 11
How to Insert new record using Lightning Component?
Hi,
I have a Component showing the List of Records already inserted for an Object. In that Component one button is there called "New". I want after clicking on "New" another Modal Pop up will open where user can insert the new values of different fields of the object and can save it. After saving Pop up will close and the List of Record component will be refreshed with the new record addition details in a row along with previously inserted record details in Separate Rows of the Record List.
Hope I could able to make you undertsnad my problem. If you can please reply with Example.
Thanks,
Debasish.
I have a Component showing the List of Records already inserted for an Object. In that Component one button is there called "New". I want after clicking on "New" another Modal Pop up will open where user can insert the new values of different fields of the object and can save it. After saving Pop up will close and the List of Record component will be refreshed with the new record addition details in a row along with previously inserted record details in Separate Rows of the Record List.
Hope I could able to make you undertsnad my problem. If you can please reply with Example.
Thanks,
Debasish.
To Insert Record using Lightnig Component:-
client side controller for this component Now create a server side controller for insert account record on the Salesforce.
For more detail please have a look on this link:-https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/qs_aotp_app_customobj.htm
Thanks
Piyush Kumar
Thanks for your reply Piyush. But I am getting following error:
Something has gone wrong. Cannot read property '$getActionDef$' of undefined.Please try again.
In gist my code is as below:
In PopupCmp.cmp
----------------------------
<input id="FDBugName" label="Name"
class="slds-input"
labelClass="slds-form-element__label"
value="{!v.FDBug.Name}"
required="true"
/>
In PoupCmpController.js
-------------------------------------
saveBugRecord : function(component, event, helper) {
//component.set("v.FDBug", event.target.FDBug);
debugger;
var newBug = component.get("v.FDBug");
console.log("FDBUG = " + newBug);
helper.createBug(component, newBug);
}
In PopupCmpHelper.js
------------------------------------
({
createBug: function(component, newBug) {
this.upsertBug(component, newBug, function(a) {
var newBug = component.get("v.FDBug");
newBug.push(a.getReturnValue());
component.set("v.FDBug", newBug);
//this.updateTotal(component);
});
},
upsertBug : function(component, newBug, callback) {
var action = component.get("c.saveFDBugRecord");
action.setParams({
"fdBugRecord": newBug
});
if (callback) {
action.setCallback(this, callback);
}
$A.enqueueAction(action);
}
})
Can you please help me identify what's the error?
Thanks,
Debasish.
@AuraEnabled
//public static FDBug__c saveFDBugRecord(FDBug__c fdBugRecord) {
public static void saveFDBugRecord(FDBug__c fdBugRecord) {
insert fdBugRecord;
//return fdBugRecord;
}
You can try like this it work fine for me.
If this one helps you please mark it as a Solve or best that helps another..
Thanks.
BTW, I am calling Insert popup Modal component from List of records Component and trying to return the control back to the List of record page after succesful save, where the List of record component will be refreshed with the new insertion value.
Mentioning specifically if CARLOS view this post, can you please put some light?
Thanks,
Debasish.
Try to put debugger and check where it was fail.
http://www.salesforceadda.com/2017/09/create-and-display-account-records.html
Create lightning component
Code as below
Name:contactform
lightning component:-
<aura:component controller="contactcontroller" >
<aura:attribute name="newContact" type="Contact" default="{ 'sobjectType': 'Contact',
'Last Name': '','Email':'','Phone':'',}"/>
<form>
<lightning:input aura:id="contactField" type="text" value="{!v.newContact.LastName}" Name="Last Name" label ="Last Name"/>
<lightning:input aura:id="contactField" type="email" name="email" label="Email" value="{!v.newContact.Email}" />
<lightning:input aura:id="contactField" type="Phone" value="{!v.newContact.Phone}" Name="Phone" label="Phone"/>
<lightning:button aura:id="contactField" label="Save Contact" onclick="{!c.savecontact}"/>
</form>
</aura:component>
Client side controller(js controller):-
({
savecontact: function(component, event, helper) {
var newcon = component.get("v.newContact");
var action = component.get("c.save");
action.setParams({
"con": newcon
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
var name = a.getReturnValue();
alert("success");
}
else
{
alert("Failed");
}
});
$A.enqueueAction(action)
}})
Server side controller
public class contactcontroller {
@AuraEnabled
public static Contact save(contact con)
{
insert con;
return con;
}
}
Lightning application:-
<aura:application >
<c:contactform/>
</aura:application>