You need to sign in to do that
Don't have an account?
Chandan Nagar
Unable to save user input data in lead object
Hi,
I have created a modal to create new lead using lightning Edit form and have included the required fields. When i am taking <lightning:inputField fieldName="Name" /> to enter the name the data gets saved but since i have a custom requirement i am using different API to enter the First Name but after clicking SAVE, the data is not getting saved and throwing an error:
"An error occured when trying to update the the record. please try again."
Please help me resolve the issue to save the whole record with Firstname as well.
<aura:component implements="lightning:actionOverride,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name="isOpen" type="boolean" default="true"/>
<aura:attribute name="activeSections" type="List" default="['Pre-Enquiry Information','Scoring and Rating','Additional Information','System Information']" />
<!--Use "slds-m-around_xx-large" class to add standard X-Large padding to the component-->
<div class="slds-m-around_xx-large">
<!--Use aura:if tag to display Model Box, on the bese of conditions. [isOpen boolean attribute] -->
<aura:if isTrue="{!v.isOpen}">
<!-- MODAL BOX Start -->
<section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<!-- MODAL BOX HEADER Start -->
<header class="slds-modal__header">
<lightning:buttonIcon iconName="utility:close"
onclick="{! c.closeModel }"
alternativeText="close"
variant="bare-inverse"
class="slds-modal__close"/>
<h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">New Pre-Enquiry</h2>
</header>
<!-- MODAL BOX BODY Part Start -->
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
<lightning:recordEditForm aura:id ="newPreEnquiry" recordId="{!v.recordId}" objectApiName="Lead" onsuccess="{!c.handleSuccess}">
<lightning:accordion allowMultipleSectionsOpen="true" activeSectionName="{!v.activeSections}">
<lightning:accordionSection name="Pre-Enquiry Information" label="Pre-Enquiry Information">
<lightning:messages />
<!-- Forming a grid of two equal columns -->
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Salutation" />
<lightning:inputField fieldName="FirstName" required="true"/>
<lightning:inputField fieldName="LastName" />
<lightning:inputField fieldName="Name" class="slds-hide"/>
<!--<lightning:inputField fieldName="Name" />-->
</div>
<div class="slds-size_1-of-2">
<div style="padding-top: 25px"><lightning:inputField fieldName="LX_Other_Title__c" /></div>
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Location__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="MobilePhone" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Email" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Other_Pre_Enquiry_Source__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Generated_By__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Category__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_PreEnquiry_Source__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Company" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Customer_Type__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Other_Preferred_Mode_of_Contact__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Enquiry_Type__c" />
</div>
</p>
</lightning:accordionSection>
</lightning:accordion>
</lightning:recordEditForm>
</div>
<!--###### MODAL BOX FOOTER Part Start ######-->
<footer class="slds-modal__footer">
<lightning:button variant="neutral"
label="Cancel"
title="Cancel"
onclick="{!c.closeModel}"/>
<lightning:button variant="brand"
type="submit"
name="save"
label="Save"
onclick="{!c.onRecordSubmit}"/>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
<!--###### MODAL BOX Part END Here ######-->
</aura:if>
</div>
</aura:component>
JS controller:
({
myAction : function(component, event, helper) {
},
openModel: function(component, event, helper) {
// for Display Model,set the "isOpen" attribute to "true"
component.set("v.isOpen", true);
},
closeModel: function(component, event, helper) {
// for Hide/Close Model,set the "isOpen" attribute to "False"
component.set("v.isOpen", false);
},
onRecordSubmit: function(component, event, helper) {
event.preventDefault(); // stop form submission
var eventFields = event.getParam("fields");
component.find('newPreEnquiry').submit(eventFields);
},
/*handleSubmit : function(cmp, event, helper) {
event.preventDefault(); // stop the form from submitting
const fields = event.getParam('fields');
fields.LastName = 'My Custom Last Name'; // modify a field
cmp.find('myRecordForm').submit(fields);
},*/
handleSuccess : function(component, event, helper) {
var preEnquiryRecord = event.getParams().response;
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": preEnquiryRecord.id,
"slideDevName": "related"
});
navEvt.fire();
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Success!',
message: 'Pre-Enquiry record created.',
duration:' 1000',
key: 'info_alt',
type: 'success',
mode: 'dismissible'
});
toastEvent.fire();
}
})
I have created a modal to create new lead using lightning Edit form and have included the required fields. When i am taking <lightning:inputField fieldName="Name" /> to enter the name the data gets saved but since i have a custom requirement i am using different API to enter the First Name but after clicking SAVE, the data is not getting saved and throwing an error:
"An error occured when trying to update the the record. please try again."
Please help me resolve the issue to save the whole record with Firstname as well.
<aura:attribute name="isOpen" type="boolean" default="true"/>
<aura:attribute name="activeSections" type="List" default="['Pre-Enquiry Information','Scoring and Rating','Additional Information','System Information']" />
<!--Use "slds-m-around_xx-large" class to add standard X-Large padding to the component-->
<div class="slds-m-around_xx-large">
<!--Use aura:if tag to display Model Box, on the bese of conditions. [isOpen boolean attribute] -->
<aura:if isTrue="{!v.isOpen}">
<!-- MODAL BOX Start -->
<section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<!-- MODAL BOX HEADER Start -->
<header class="slds-modal__header">
<lightning:buttonIcon iconName="utility:close"
onclick="{! c.closeModel }"
alternativeText="close"
variant="bare-inverse"
class="slds-modal__close"/>
<h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">New Pre-Enquiry</h2>
</header>
<!-- MODAL BOX BODY Part Start -->
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
<lightning:recordEditForm aura:id ="newPreEnquiry" recordId="{!v.recordId}" objectApiName="Lead" onsuccess="{!c.handleSuccess}">
<lightning:accordion allowMultipleSectionsOpen="true" activeSectionName="{!v.activeSections}">
<lightning:accordionSection name="Pre-Enquiry Information" label="Pre-Enquiry Information">
<lightning:messages />
<!-- Forming a grid of two equal columns -->
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Salutation" />
<lightning:inputField fieldName="FirstName" required="true"/>
<lightning:inputField fieldName="LastName" />
<lightning:inputField fieldName="Name" class="slds-hide"/>
<!--<lightning:inputField fieldName="Name" />-->
</div>
<div class="slds-size_1-of-2">
<div style="padding-top: 25px"><lightning:inputField fieldName="LX_Other_Title__c" /></div>
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Location__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="MobilePhone" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Email" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Other_Pre_Enquiry_Source__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Generated_By__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Category__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_PreEnquiry_Source__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Company" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Customer_Type__c" />
</div>
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Other_Preferred_Mode_of_Contact__c" />
</div>
</p>
<p class="slds-grid">
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="LX_Enquiry_Type__c" />
</div>
</p>
</lightning:accordionSection>
</lightning:accordion>
</lightning:recordEditForm>
</div>
<!--###### MODAL BOX FOOTER Part Start ######-->
<footer class="slds-modal__footer">
<lightning:button variant="neutral"
label="Cancel"
title="Cancel"
onclick="{!c.closeModel}"/>
<lightning:button variant="brand"
type="submit"
name="save"
label="Save"
onclick="{!c.onRecordSubmit}"/>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
<!--###### MODAL BOX Part END Here ######-->
</aura:if>
</div>
</aura:component>
JS controller:
({
myAction : function(component, event, helper) {
},
openModel: function(component, event, helper) {
// for Display Model,set the "isOpen" attribute to "true"
component.set("v.isOpen", true);
},
closeModel: function(component, event, helper) {
// for Hide/Close Model,set the "isOpen" attribute to "False"
component.set("v.isOpen", false);
},
onRecordSubmit: function(component, event, helper) {
event.preventDefault(); // stop form submission
var eventFields = event.getParam("fields");
component.find('newPreEnquiry').submit(eventFields);
},
/*handleSubmit : function(cmp, event, helper) {
event.preventDefault(); // stop the form from submitting
const fields = event.getParam('fields');
fields.LastName = 'My Custom Last Name'; // modify a field
cmp.find('myRecordForm').submit(fields);
},*/
handleSuccess : function(component, event, helper) {
var preEnquiryRecord = event.getParams().response;
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": preEnquiryRecord.id,
"slideDevName": "related"
});
navEvt.fire();
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Success!',
message: 'Pre-Enquiry record created.',
duration:' 1000',
key: 'info_alt',
type: 'success',
mode: 'dismissible'
});
toastEvent.fire();
}
})
You can use any one of the below ways for this then you will not get any error:
Just replace the below lines from your code with the below highlighted ones:
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Salutation" />
<lightning:inputField fieldName="FirstName" required="true"/>
<lightning:inputField fieldName="LastName" />
<lightning:inputField fieldName="Name" class="slds-hide"/>
<!--<lightning:inputField fieldName="Name" />-->
</div>
Method 1 :
<div class="slds-size_1-of-2">
<div style="display:none">
<lightning:inputField fieldName="Name"/>
</div>
<lightning:inputField fieldName="Salutation" required="true"/>
<lightning:inputField fieldName="FirstName" required="true"/>
<lightning:inputField fieldName="LastName" required="true" />
</div>
(OR)
Method 2 : simple use the below one line it will ask you to enter the Salutation, First Name, Last Name
<div class="slds-size_1-of-2">
<lightning:inputField fieldName="Name" />
</div>
One More thing if you are using the RecordEditForm only for record creation then no need of RecordId atribute in below line.
<lightning:recordEditForm aura:id ="newPreEnquiry" objectApiName="Lead" onsuccess="{!c.handleSuccess}">
Thanks,
Maharajan.C