[SalesForce] lightning:recordEditForm not working without force:recordData

The recordEditForm is not supposed to need the Lightning data service provided by recordData however in the below example the only time fields beyond the first one show up are if I also include the recordData component.


<aura:component description="Example" access="global">

<aura:attribute name="componentError" type="String" access="private"
                description="An error message to display instead of the component"/>

<aura:attribute name="payeeRecordId" type="String" access="global"/>
<aura:attribute name="payeeObjectType" type="String" required="true" access="global" default="Contact"/>
<aura:attribute name="payeeRecordFields"type="Object" access="private"/>
<aura:attribute name="payeeRecordFieldList" type="String[]" access="global" default="FirstName, LastName"/>

<aura:attribute name="payeeRecord" type="Object" access="private"/>

<aura:attribute name="payeeRecordError" type="String" access="private"/>

<aura:if isTrue="{!not(empty(v.componentError))}">

    <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_error" role="alert">
        <span class="slds-assistive-text">Error</span>
        <span class="slds-icon_container slds-icon-utility-error slds-m-right_x-small"
              title="Description of icon when needed">
            <lightning:icon variant="inverse" iconName="utility:error" size="x-small"/>

    <aura:set attribute="else">
        <force:recordData aura:id="payeeRecord"

        <lightning:recordEditForm recordId="{!v.payeeRecordId}" objectApiName="{!v.payeeObjectType}">
            <aura:iteration items="{!v.payeeRecordFieldList}" var="f">
                <lightning:inputField fieldName="{!f}"/>



With Record Data

However if I remove the force:recordData component only the first field gets output

Without recordData


I am trying to provide a way for the user of the component to specify which fields get presented for input.

Best Answer


Based on your latest edits, you have the attribute populated as below:

<aura:attribute name="payeeRecordFieldList" type="String[]" access="global" 
                default="FirstName, LastName"/>

Having spaces in the field names did not work for me. Later, referring to the excerpt from the documentation, seems this may have been the issue here.

To set a default value, surround comma-separated values with []; for example default="['red', 'green', 'blue']". Setting a default value without square brackets is deprecated and can lead to unexpected behavior.

This is what I think was happening in this case when being used with force:recordData (LDS) implementation. LDS would have taken care of removing spaces from the attribute payeeRecordFieldList And that without LDS because the field names are separated with a comma and a space in there, it never worked because of the explanation as in documentation.

In my example below, the field names worked without having spaces between it and then later with the approach as mentioned in the documentation.

You don't need a force:recordData implementation here. As long as your attribute payeeRecordFieldList is populated and consists of the fields you want to display on your form, you should be able to render those fields in your lightning:recordEditForm.

You may like to verify if the attribute payeeRecordFieldList is populated correctly or not.

As an example, I used your code with few minor modifications and removed the force:recordData piece and after declaring the attribute as below, the fields were rendered appropriately.

<!-- other code -->
<aura:attribute name="payeeRecordFieldList" type="String[]"  access="global" 
                default="FirstName,LastName,AccountId" />


<aura:attribute name="payeeRecordFieldList" type="String[]"  access="global" 
                default="['FirstName'], ['LastName'], ['AccountId']" />

<!-- other code -->
<!-- removed LDS force:recordData implementation -->
<lightning:recordEditForm recordId="{!v.payeeRecordId}" objectApiName="{!v.payeeObjectType}">
    <aura:iteration items="{!v.payeeRecordFieldList}" var="f">
        <lightning:inputField fieldName="{!f}"/>

enter image description here