Play Games

Search This Blog

Monday, August 8, 2016

force:recordView tag in Lightning Component

force:recordView tag is used to display a record in read-only view.
The record can be displayed in 2 different layouts.By default, the record view uses the full layout to display all fields of the record.
1) MINI -- The mini layout displays the name field and any associated parent record field.
2) FULL --displays all fields of the record.
Example :
AppToDisplayRecordView.app :
<aura:application >
    <ltng:require styles="{!$Resource.SLDS100 +
         '/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
    <div class="slds">
         <c:DisplayRecordView />
    </div>
</aura:application>

DisplayRecordView.cmp :
<aura:component >
<force:recordView recordId="00328000003Z3Ih" type="MINI"/>
</aura:component>
Note : "00328000003Z3Ih" is the contactId in my instance.Replace this with the contactId of the contact present in your instance.
Output:

Modify the above component to display in FULL layout.
<aura:component >
<force:recordView recordId="00328000003Z3Ih" type="FULL"/>
</aura:component>
Output:

2 comments:

  1. Is there a way to dynamically pass a record ID to ?

    For example, I am trying to show a child record on my Contact record page. I store that child record's ID in a custom field on the Contact record. Can I pass that value to the recordView?

    ReplyDelete
    Replies
    1. You can provide a dynamic ID for the recordId attribute using the format {!v.myObject.recordId}. To load record data, wire up the container component to an Apex controller that returns the data. See Working with Salesforce Records in the Lightning Components Developer Guide for more information.

      URL - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_force_recordView.htm

      Delete