<aura:iteration items="{!v.oppStageList}" var="opp"><lightning:recordEditForm aura:id = "StageChange" recordId ="{!opp.Id}" objectApiName ="Opportunity" onsuccess ="{!c.handleSuccess}" onsubmit="{!c.handleSubmit}">

                        <lightning:messages />
                        <lightning:layout multipleRows="true">
                            <lightning:layoutItem padding="around-medium" size="1">
                                <lightning:outputField aura:id="Owner" fieldName="OwnerId" variant="label-hidden"/>
                            <lightning:layoutItem padding="around-medium" size="1">
                                <lightning:outputField aura:id="Name" fieldName="Name" variant="label-hidden"/>

                            <lightning:inputField aura:id="approved" fieldName="Stage_Approved__c" variant="label-hidden" class="HideFields"/>
                            <lightning:layoutItem padding="around-small" size="2">
                                    <lightning:button disabled="{!v.disabled}" variant="success" name="save" label="Approve" type="submit" class="slds-m-right_x-small"/>
                                    <lightning:button disabled="{!v.disabled}" variant="destructive" type="submit" name="save" label="Reject" />

JS controller:

handleSubmit: function(component, event, helper) {
    //event.preventDefault(); // stop form submission
    var eventFields = event.getParam('fields');
    eventFields["Stage_Approved__c"] = true;
    component.find("StageChange").forEach( form =>{
    component.set('v.showSpinner', true);

handleSuccess: function(component, event, helper) {
    component.set('v.showSpinner', false);
  • which single record you want to submit? like if u have 10 items in v.oppStageList attribute which one you want to submit? – sdandamud1 Oct 3 '19 at 18:27
  • @sdandamud1: it can be any record based on the save action out of 10. So how will I identify which one to save? The one in the JS controller where I am using forEach saves all the records if I clicked on any of the save action on any of the record. – hardikace29 Oct 4 '19 at 0:56

In your controller markup, I am running for-loop on component.find("StageChange") and break it after one iteration. event.getParam('fields'); returns the row where the button has been pressed. You don't need to submit everything in component.find("StageChange") list.

handleSubmit: function(component, event, helper) {
    var eventfields= event.getParam('fields');
    for(var key in component.find("StageChange")){
  • I am getting eventFields["Id"] and event.getSource().get("v.name") bopth as 'undefined' – hardikace29 Oct 4 '19 at 10:21
  • @hardikace29 please find the updated code. – sanket kumar Oct 4 '19 at 15:58
  • how do I use selectedrecordid in handleSubmit? @sanket kumar – hardikace29 Oct 6 '19 at 5:34
  • @hardikace29 I have updated the code. You don't need the aura:attribute at all. – sanket kumar Oct 8 '19 at 11:12
  • thanks! That worked @Sanket – hardikace29 Oct 10 '19 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.