You need to sign in to do that
Don't have an account?
Varun MK
I have written the above code to insert a record from the page that I created. When I press the submit button I get the error below.
Can any1 let me know what I am doing wrong?
Record Insertion from Lightning Page
CMP:- <aura:component controller="houseHoldServicesCtrl"> <aura:attribute name="Registration" type="Registration__c"/> <aura:attribute name="isMdlBxOpnLgn" type="boolean" default="false"/> <aura:attribute name="isMdlBxOpnReg" type="boolean" default="false"/> <!-- LOGIN MODAL BOX START --> <div class="RHS_button"> <lightning:button label="Login" onclick="{!c.openModalBoxLgn}" class="slds-button slds-button_outline-brand" iconPosition="right" /> <aura:if isTrue="{!v.isMdlBxOpnLgn}"> <!--###### 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.closeModalBox}" alternativeText="close" variant="bare-inverse" class="slds-modal__close"/> <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Login Page</h2> </header> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1"> <c:houseHoldServices_Login/> </div> <!--###### MODAL BOX FOOTER Part Start ######--> <footer class="slds-modal__footer"> <lightning:button label="Login !" onclick="" class="slds-button slds-button_outline-brand" /> <lightning:button label="Reset" onclick="" class="slds-button slds-button_outline-brand" /> <lightning:button label="Go Back" onclick="" class="slds-button slds-button_outline-brand" /> </footer> </div> </section> <div class="slds-backdrop slds-backdrop_open"></div> <!--###### MODAL BOX Part END Here ######--> </aura:if> </div> <!-- LOGIN MODAL BOX END --> <!-- REGISTRATION MODAL BOX START --> <div class="RHS_button"> <lightning:button label="Register / SignUp" onclick="{!c.openModalBoxReg}" class="slds-button slds-button_outline-brand" /> </div> <aura:if isTrue="{!v.isMdlBxOpnReg}"> <!--###### 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.closeModalBox}" alternativeText="close" variant="bare-inverse" class="slds-modal__close"/> <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Registration Page</h2> </header> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1"> <lightning:input aura:id="EmaiL" value="{!v.Registration.EmaiL__c}" placeholder="Em@iL"/> <lightning:input aura:id="MobileNumber" value="{!v.Registration.Mobile_Number__c}" placeholder="Mobile Number"/> <lightning:input aura:id="Username" value="{!v.Registration.Username__c}" placeholder="Username"/> <lightning:input aura:id="Password" value="{!v.Registration.Password__c}" placeholder="Password"/> </div> <!--###### MODAL BOX FOOTER Part Start ######--> <footer class="slds-modal__footer"> <lightning:button label="Submit to Register !" onclick="{!c.registerUser}" class="slds-button slds-button_outline-brand" /> <lightning:button label="Reset" onclick="" class="slds-button slds-button_outline-brand" /> <lightning:button label="Go Back" onclick="" class="slds-button slds-button_outline-brand" /> </footer> </div> </section> <div class="slds-backdrop slds-backdrop_open"></div> <!--###### MODAL BOX Part END Here ######--> </aura:if> <!-- REGISTRATION MODAL BOX END --> <div class="LHS_button"> <lightning:button label="Contact Us" onclick="" class="slds-button slds-button_outline-brand" iconPosition="right" /> | <lightning:button label="About Us" onclick="" class="slds-button slds-button_outline-brand" /> </div> <div class="title"> header </div> </aura:component> --------------------------------------------------------------------------------- clientSide Controller :- registerUser :function(component,event,helper){ debugger; helper.regHelpr(component); } ---------------------------------------------------- helper:- ({ regHelpr : function(component) { debugger; var strEmaiL = component.find("EmaiL").get("v.value"); var strMobileNumber = component.find("MobileNumber").get("v.value"); var strUsername = component.find("Username").get("v.value"); var strPassword = component.find("Password").get("v.value"); var action = component.get("c.submit"); action.setParams({ "EmaiL" :strEmaiL, "MobileNumber" :strMobileNumber, "Username" :strUsername, "Password" :strPassword }); action.setCallback(this,function(response){ component.set("v.Registration",response.getReturnValue()); }); component.set("v.isMdlBxOpnReg",false); $A.enqueueAction(action); } }) ---------------------------------------------------------- serverSide Controller APEX CLASS public class houseHoldServicesCtrl { @AuraEnabled public static void submit(String EmaiL,String MobileNumber,String Username,String Password){ Registration__c regstr = new Registration__c(); regstr.EmaiL__c = EmaiL; regstr.Mobile_Number__c = MobileNumber; regstr.Username__c = Username; regstr.Password__c = Password; Database.Insert(regstr); } }
I have written the above code to insert a record from the page that I created. When I press the submit button I get the error below.
Can any1 let me know what I am doing wrong?
Try the below changes:
Label is Mandatory Attribute in the Lightning:Input as per the Documentation:
so add the Label inside all the Ligthning:Input tag as like below:
<lightning:input aura:id="EmaiL" label="Email"
value="{!v.Registration.EmaiL__c}"
placeholder="Em@iL"/>
<aura:attribute name="Registration" type="Registration__c" default="{'sobjectType':'Registration__c', 'EmaiL__c':'', 'Mobile_Number__c':'','Username__c':'','Password__c':''}"/>
helper:-
({
regHelpr : function(component) {
debugger;
var action = component.get("c.submit");
action.setParams({
"regRecord" :component.get("v.Registration")
});
action.setCallback(this,function(response){
component.set("v.Registration",response.getReturnValue());
});
component.set("v.isMdlBxOpnReg",false);
$A.enqueueAction(action);
}
})
----------------------------------------------------------
----------------------------------------------------------
serverSide Controller APEX CLASS
public class houseHoldServicesCtrl {
@AuraEnabled
public static void submit(Registration__c regRecord){
try{
insert regRecord;
}
catch(Exception ex)
{
}
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Maharajan.C