Below lightning component is from Lightning data service module
in trailhead
Questions 1: Why there are two object attributes used - record , simpleRecord
, when one attribute can serve the purpose. Is there any reason to use a different attribute in target field?
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> <!--inherit recordId attribute-->
<aura:attribute name="record" type="Object" description="The record object to be displayed"/>
<aura:attribute name="simpleRecord" type="Object" description="A simplified view record object to be displayed"/>
<aura:attribute name="recordError" type="String" description="An error message bound to force:recordData"/>
<force:recordData aura:id="record"
layoutType="FULL"
recordId="{!v.recordId}"
targetError="{!v.recordError}"
targetRecord="{!v.record}"
targetFields="{!v.simpleRecord}"
mode="VIEW"/>
<!-- Display a lightning card with details about the record -->
<div class="Record Details">
<lightning:card iconName="standard:account" title="{!v.simpleRecord.Name}" >
<div class="slds-p-horizontal--small">
<p class="slds-text-heading--small">
<lightning:formattedText title="Billing City" value="{!v.simpleRecord.BillingCity}" /></p>
<p class="slds-text-heading--small">
<lightning:formattedText title="Billing State" value="{!v.simpleRecord.BillingState}" /></p>
</div>
</lightning:card>
</div>
<!-- Display Lightning Data Service errors, if any -->
<aura:if isTrue="{!not(empty(v.recordError))}">
<div class="recordError">{!v.recordError}</div>
</aura:if>
</aura:component>
Question 2 - Record Data has an attribute fields="{!v.fieldsToQuery}"
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_force_recordData.htm
If fields
attribute left blank or unused would we unable to display it in the UI? I see the targetFields attribute is used to display field in the UI below. What is the significance of using Fields
- appreciate an example if possible.
<div class="Record Details">
<lightning:card iconName="standard:account" title="{!v.simpleRecord.Name}" >
<div class="slds-p-horizontal--small">
<p class="slds-text-heading--small">
<lightning:formattedText title="Billing City" value="{!v.simpleRecord.BillingCity}" /></p>
<p class="slds-text-heading--small">
<lightning:formattedText title="Billing State" value="{!v.simpleRecord.BillingState}" /></p>
</div>
</lightning:card>
</div>