0

I have a requirement where I need to update a lookup field on every child record (while working with the parent records). My plan is to create a lightning component and iterate over lightning:recordEditForm to show the needed lookup fields:

<aura:component controller="EditFormTestController"
                implements="flexipage:availableForAllPageTypes,force:appHostable,force:lightningQuickAction,force:hasRecordId">

    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <aura:attribute name="quoteRatePlanList" type="zqu__QuoteRatePlan__c[]"/>

    <lightning:card title="FormTest9">
        <div aura:id="recordEditForm">
            <aura:iteration items="{!v.quoteRatePlanList}" var="quoteRatePlan">
                <lightning:recordEditForm aura:id="editForm" recordId="{!quoteRatePlan.Id}"
                                          objectApiName="zqu__QuoteRatePlan__c">
                    <lightning:inputField fieldName="Usage_Tenant__c"/>
                </lightning:recordEditForm>
            </aura:iteration>
        </div>

        <aura:set attribute="actions">
            <lightning:button variant="brand" label="Update" name="update" onclick="{!c.update}"/>
        </aura:set>
    </lightning:card>

</aura:component>

This displays the needed input fields, but i'm not able to get the actual update to work. Looking at some examples it should be possible to do something like this:

({
    init: function (cmp, event, helper) {
        helper.fetchPlans(cmp, event, helper);
    },

    update: function (cmp, event, helper) {
        var editedRecordList = cmp.find("editForm");
        for (var i = 0; i < editedRecordList.length; i++) {
            editedRecordList.submit();
        }
    }
});

This results in the following error:

Uncaught Action failed: c:EditRecordTest$controller$update [editedRecordList.submit is not a function]

Does anyone know how to update all records in one button click? Using an Apex controller for this would also be fine, just not sure how to get this working.

Thanks!

3
  • 1
    Try this in your update controller.. cmp.find("editForm").forEach( form =>{ form.submit(); }) Sep 20, 2019 at 15:30
  • Thanks @PrudhviKonda! Thats works :) Sep 20, 2019 at 15:36
  • @RuudDirksen Did that worked? I ran into the same problem. it is saving only the last record but not all the records. May 21, 2020 at 17:09

0

You must log in to answer this question.

Browse other questions tagged .