Tuesday, May 28, 2019

Viewing a record using LDS (force:recordData)

Here we taking a simple example to see how to use force:recordData to view the record.

Put the below component in account record detail page.

viewcomp.cmp

<aura:component implements="force:hasRecordId,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global" >
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="recordFieldsToQuery" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <force:recordData aura:id="savingRecord"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      mode="VIEW"
                      targetRecord="{!v.record}"
                      targetFields="{!v.recordFieldsToQuery}"
                      targetError="{!v.recordError}"
                      />
    <!--We are using lightning card to display fields of account object-->
 
    <lightning:card iconName="action:preview" title="View Account">
        <div class="slds-p-horizontal--small">
            <lightning:formattedText title="Account name" value="{!v.recordFieldsToQuery.Name}"/>
            <br/>
            <lightning:formattedText title="Account billing city" value="{!v.recordFieldsToQuery.BillingCity}" />
         
        </div>
    </lightning:card>
</aura:component>
Put the above component on account record detail page.

OUTPUT:


Viewing a record using LDS (force:recordData)

No comments:

Post a Comment