function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AndrewTaylorAndrewTaylor 

Loading a Record using force.recordData targetFields

I'm having difficulty using force:recordData to load some data for a record in a Lightning component.
 
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="fieldsToQuery" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.record}"
                      targetError="{!v.recordError}"
                      targetFields="{!v.fieldsToQuery}"
                      />
    {!v.fieldsToQuery.Name}
    <br/>
    {!v.fieldsToQuery.MailingAddress}<br />
    {!v.fieldsToQuery.MailingCity}, {!v.fieldsToQuery.MailingState} {!v.fieldsToQuery.MailingPostalCode}<br />
    {!v.fieldsToQuery.MailingCountry}
</aura>

In the above, the data does not render on the page; if I try to specifically set the fields in force:recordData, it doesn't help either. Is there something I'm missing on this?
Best Answer chosen by AndrewTaylor
sfdcMonkey.comsfdcMonkey.com
hi your component is working fine, you just need to remove {!v.fieldsToQuery.MailingAddress} , because this is an aggregate field so we can not showedit  whole mailing address
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="fieldsToQuery" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.record}"
                      targetError="{!v.recordError}"
                      targetFields="{!v.fieldsToQuery}"
                      />
    {!v.fieldsToQuery.Name}
    <br/>
  
    {!v.fieldsToQuery.MailingCity}, {!v.fieldsToQuery.MailingState} {!v.fieldsToQuery.MailingPostalCode}<br />
    {!v.fieldsToQuery.MailingCountry}

	
</aura:component>

steps to check this lightning component : [result only showing when we add this component to object(contact) detail page]

In lightning experience >> open any of contact record detail page and from top settings icon select edit page 
User-added image

drag your lightning component on detail page 
User-added image

save and active your page and see the output on your contact detail page 

User-added image

i hope it helps you.
   Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others ,thanks    
http://sfdcmonkey.com  (http://sfdcmonkey.com )

All Answers

sfdcMonkey.comsfdcMonkey.com
hi your component is working fine, you just need to remove {!v.fieldsToQuery.MailingAddress} , because this is an aggregate field so we can not showedit  whole mailing address
<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="fieldsToQuery" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.record}"
                      targetError="{!v.recordError}"
                      targetFields="{!v.fieldsToQuery}"
                      />
    {!v.fieldsToQuery.Name}
    <br/>
  
    {!v.fieldsToQuery.MailingCity}, {!v.fieldsToQuery.MailingState} {!v.fieldsToQuery.MailingPostalCode}<br />
    {!v.fieldsToQuery.MailingCountry}

	
</aura:component>

steps to check this lightning component : [result only showing when we add this component to object(contact) detail page]

In lightning experience >> open any of contact record detail page and from top settings icon select edit page 
User-added image

drag your lightning component on detail page 
User-added image

save and active your page and see the output on your contact detail page 

User-added image

i hope it helps you.
   Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others ,thanks    
http://sfdcmonkey.com  (http://sfdcmonkey.com )
This was selected as the best answer
AndrewTaylorAndrewTaylor
Thanks piyush_soni