I am new to Lightning Component Design and I am trying to use the lightning:recordForm to display related record detail on the case object. I can get the fields to show and the lightning component to display on the case but it shows no data even when the case has a contact assigned. Below is the code I have been trying to use but I cannot seem to get it to populate with data. Any help is much appreciated. Thanks
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
<aura:attribute name="recordId" type="Id"/>
<aura:attribute name="case" type="Case"/>
<aura:attribute name="contactFields" type="String[]" default="Name,Title"/>
<force:recordData aura:id="caseRecord"
recordId="{!v.recordId}"
targetFields="{!v.Case}"
layoutType="FULL"/>
<lightning:card iconName="standard:user" title="{! 'Contact Details'}">
<div class="slds-p-left_large slds-p-right_medium">
<lightning:recordForm aura:id="ContactForm"
recordId="{!v.Case.ContactId}"
objectApiName="Contact"
fields="{!v.contactFields}"
columns="2"
mode="View"/>
</div>
</lightning:card>
Best Answer
Your primary issue is here where you defining
targetFields="{!v.Case}"
AND
here where you are defining
recordId="{!v.Case.ContactId}"
The issue: case sensitivity
You have the attribute declared as
<aura:attribute name="case" type="Case"/>
with alowercase c
, and that you are trying to reference it with anUPPERCASE C
as mentioned in the places above.Once you change the references of the attribute at the places wherever it is referred, as below (or better rename it not to conflict with the object name to say
myCase
), it will work.Change:
targetFields="{!v.Case}"
TOtargetFields="{!v.case}"
(to start with lowercase c)recordId="{!v.Case.ContactId}"
TOrecordId="{!v.case.ContactId}"
(to start with lowercase c)Additionally, on top of this you should also remove reference of the below declaration:
This may lead to a runtime error, as you are already implementing force:recordId which mentions (emphasis mine):