You need to sign in to do that
Don't have an account?
Sid Lightning
Save button on lightning component ?
Hi,
I want to create a save button on lightning component for my object Shipping Address which is child to parent Account.
There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component
I am tricked about how do i save it into database and get it displayed on my screen.
Can anyone help me on this please
I want to create a save button on lightning component for my object Shipping Address which is child to parent Account.
There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component
I am tricked about how do i save it into database and get it displayed on my screen.
Can anyone help me on this please
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. I have used Contact object. Kindly modify the code as per your requirement.
Apex:
Component:
Controller:
CSS:
Application:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Try following code for saving:
Component:
Class:
After this you can use lightning datatable component to display them, here is the link: http://www.sfdcpoint.com/salesforce/lightning-datatable-example-salesforce/
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I am getting this error, while trying to execute your code
Uncaught Action failed: c:ProductAddressScreen$controller$handleSelect [component is not defined]
Function : object.saveAddress
Below is my code.
Component :
<aura:attribute name="selectedAddress" type="Shipping_Address__c" default="{Name : '',
Shipping_City__c : ''}"/>
<lightning:buttonMenu iconName="utility:down" class="slds-float_right dropdown" onselect="{! c.handleSelect}">
<lightning:menuItem label="Save Address" value="Save Address"/>
</lightning:buttonMenu>
Controller :
if(selectedMenuItemValue == 'Save Address'){
helper.saveAddress(cmp, event, helper)
}
Helper :
saveAddress : function (cmp, event, helper){
var regForm = component.get("v.selectedAddress");
var action = component.get("c.saveDetails");
action.setParams({sha : selectedAddress});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var res = response.getReturnValue();
component.set('v.recordId',res);
component.set("v.showDetails", true);
alert('Successfully Saved' + res);
component.set('v.selectedAddress','');
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " + errors[0].message);
}
}
else {
console.log(response.getReturnValue());
}
}
});
$A.enqueueAction(action);
},
Can you please suggest. I have already done the change you suggested. still the same error
<aura:attribute name="accountId" type="Id"/>
<aura:attribute name="selectedAddress" type="Shipping_Address__c" default="{Name : '',
Shipping_City__c : ''}"/>
<aura:attribute name="flatTypeValues" type="String[]"/>
<aura:attribute name="error" type="String"/>
<aura:attribute name="showDetails" type="boolean" default="false" />
<lightning:buttonMenu iconName="utility:down" class="slds-float_right dropdown" onselect="{! c.handleSelect}">
<lightning:menuItem label="Save Address" value="Save Address"/>
<lightning:menuItem label="Confirm Address" value="Confirm Address"/>
<lightning:menuItem label="Search Pincode" value="Search Pincode" aura:id="searchPincode"/>
</lightning:buttonMenu>
Controller :
handleSelect: function (cmp, event, helper) {
var selectedMenuItemValue = event.getParam("value");
if(selectedMenuItemValue == 'Confirm Address'){
// console.log('confirming address');
// console.log('val:',cmp.get('v.selectedAddress'));
helper.validateConfirmAdd(cmp, event, helper);
}
else if(selectedMenuItemValue == 'Save Address'){
helper.saveAddress(cmp, event, helper);
}
else if(selectedMenuItemValue == 'Search Pincode'){
// console.log('search pincode');
helper.enableSearchPincode(cmp, event, helper);
}
}
Helper:
saveAddress : function(cmp, event, helper){
var regForm = cmp.get("v.selectedAddress");
var action = cmp.get("c.saveDetails");
action.setParams({sha : regForm});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var res = response.getReturnValue();
cmp.set('v.recordId',res);
cmp.set("v.showDetails", true);
alert('Successfully Saved' + res);
cmp.set('v.selectedAddress','');
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " + errors[0].message);
}
}
else {
console.log(response.getReturnValue());
}
}
});
$A.enqueueAction(action);
and data is getting saved
Greetings to you!
- Please use the code {Solved} : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
I ave 6 fields that i want to save and display on page. Will this solution save all the 6 fields.. I dont see we are passing all the 6 fields. I havent wokred on lightning before.. so not sure
Code is throwing error .
ProductAddressScreen$controller$handleSelect [selectedAddress is not defined]
Can you help me over the same/
Can you please help
Can you please help me with this code