Lightning Record Form – Account Object Lookup Bug

Final update

See my answer below for the issues. I believe there is a bug in the implementation as well. The lookup will not work if the field is not on the page layout configuration.

The weird part is, as long as any field that looks up to the same object is on the layout then the field you are actually using for the form does not have to be on the layout….

Question for reference

On a scratch org….

This is on a Lightning Tab NOT a record detail page. I am populating the recordId via attribute and it is working to get the record as the lookup to a custom object for the record is working. Only standard object lookups are not working.

Trying to build a simple form to populate an account lookup on a record. The Account object is supported according to the documentation but the following does not work:

Markup – Nothing else exists. Sitting on a lightning tab

<aura:component description="testcmp" implements="force:appHostable">
    <aura:attribute name="theFields" type="List" default="
           ['Name','ns__Lookup_ToCustom__c', 'ns__Account__c']" />

    <lightning:recordForm aura:id="recordViewForm"
                          recordId="{!v.theId}"
                          objectApiName="ns__CustomObject__c"
                          mode="edit" columns="2" fields="   
                          {!v.theFields}"
    >
<aura:component>

When the above is used the ns__LookupToCustom__c works just fine but the lookup to Accountns__Account__c does not works and the following error is thrown in the console for the Account lookup field:

TypeError: Cannot read property 'label' of undefined
    at wiredItems.c.map.a (lightning-lookup-desktop.js:2)
    at Array.map (<anonymous>)
    at U.wiredLookups (lightning-lookup-desktop.js:2)
    at r.dispatchEvent (aura_prod.js:3)
    at Object.next (force-wire-adapter.js:2)
    at W.next (force-lds-cache.js:2)
    at X.v (force-lds-cache.js:2)
    at subscriptions.size.subscriptions.forEach.t (force-lds-cache.js:2)
    at Set.forEach (<anonymous>)
    at X.emitValue (force-lds-cache.js:2)

System admin profile with access to the Account Field…APIVersion 43.0

All I am trying to do is a quick form with a lightning lookup and since there is no component to perform a lookup with typeahead etc this was a quick way to do it but…..

Anyone know of a way to get the lookup to the Account working?

Note: I added a contact lookup and tried that and the same thing happened. So happens on both account and contact

Images…

  1. The first lookup is a lookup to a custom object and it works
  2. The second lookup is to the account object and does not work, console shows above error

enter image description here
enter image description here

I tried to change the field list attribute to:

<aura:attribute name="theFields" type="String[]" default="Name,     
    ns__Lookup_ToCustom__c, ns__Account__c"/>

and the weird thing that happened is the Account lookup was removed from the form completely……

Thinking maybe something to do with a namespace custom object having a look up to a standard object?

Best Answer

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    <aura:attribute name="contactfield" type="String[]" default="LastName,AccountId"/>    
    <Lightning:Card class="slds-card__body slds-card__body_inner" iconname="Standard:Contact"
                    title="quick contact">
    <lightning:recordForm aura:id="brokerForm"
                                recordId="{!v.recordId}"
                                objectApiName="Contact"
                                fields="{!v.contactfield}"
                                mode="edit"/>
    </Lightning:Card>
</aura:component>

This works for me. May be this recordId="{!v.theId}" is creating peoblem for you. Are you getting any error while adding component to layout?enter image description here

Update:-

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

<aura:attribute name="Branchfield" type="String[]" default="Name,ACCOUNTCHILD__c,Account__c"/>    
<Lightning:Card class="slds-card__body slds-card__body_inner" iconname="Standard:Contact"
                title="quick Branch">
<lightning:recordForm aura:id="brokerForm"
                            recordId="a0T7F000006EEbPUAW"
                            objectApiName="Branch__c"
                            fields="{!v.Branchfield}"
                            mode="edit"/>
</Lightning:Card>

Here i tried with Lightning tab on custom object having a standard object and another with custom object lookup. Is that matching with you what you want? enter image description here

Update:-

I tried with custom Object having a namespace and working fine:-

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

<aura:attribute name="Branchfield" type="list" default="['Name','sa_nket__ACCOUNTCHILD__c','sa_nket__Account__c']"/>    
<Lightning:Card class="slds-card__body slds-card__body_inner" iconname="Standard:Contact"
                title="quick Branch">
<lightning:recordForm aura:id="brokerForm"
                            recordId="a0T7F000006EEbP"
                            objectApiName="sa_nket__Branch__c"
                            fields="{!v.Branchfield}"
                            mode="edit"/>
</Lightning:Card>

enter image description here