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!

  • 1
    Try this in your update controller.. cmp.find("editForm").forEach( form =>{ form.submit(); }) – Prudhvi Konda Sep 20 at 15:30
  • Thanks @PrudhviKonda! Thats works :) – Ruud Dirksen Sep 20 at 15:36

Your Answer

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

Browse other questions tagged or ask your own question.