Activity › Forums › Salesforce® Discussions › What is the use of force:recordData in Salesforce lightning component?
Tagged: Custom Action, force:recordData, Lightning App, Lightning Data Service, Record ID, Salesforce Lightning Component, Salesforce Records, Standard Account
-
What is the use of force:recordData in Salesforce lightning component?
Posted by Nikita on September 25, 2019 at 11:53 AMWhat is the use of force:recordData in salesforce lightning component?
Ashutosh replied 6 years, 7 months ago 2 Members · 1 Reply -
1 Reply
-
A force:recordData component defines the parameters for accessing, modifying, or creating a record using Lightning Data Service. You have granular control on how you want to display or render the data in your custom component.
We recommend that you use the simpler lightning:recordForm component for accessing, modifying, or creating a record if you don’t need a custom layout or custom rendering of record data.
To load a record, specify its record ID, the component attributes, and a list of fields in your custom component. You can add your custom component to a record home page in the Lightning App Builder, or as a custom action.
In the following example, the record ID is supplied by the implicit recordId attribute added by the force:hasRecordId interface. A lightning:card component is used to display the record data via accountRecord on the targetFields attribute.<aura:component implements=”force:hasRecordId,flexipage:availableForRecordHome”>
<aura:attribute name=”accountRecord” type=”Object”/>
<aura:attribute name=”recordLoadError” type=”String”/><force:recordData aura:id=”recordLoader”
recordId=”{!v.recordId}”
fields=”Name,Description,Phone,Industry”
targetFields=”{!v.accountRecord}”
targetError=”{!v.recordLoadError}”
/><div>
<lightning:card iconName=”standard:account” title=”{!v.accountRecord.Name}” >
<div class=”slds-p-horizontal–small”>
<p class=”slds-text-heading–medium”><lightning:formattedPhone title=”Phone” value=”{!v.accountRecord.Phone}” /></p>
<p class=”slds-truncate”><lightning:formattedText title=”Description” value=”{!v.accountRecord.Description}” /></p>
<p class=”slds-truncate”> <lightning:formattedText title=”Industry” value=”{!v.accountRecord.Industry}” /></p>
</div>
</lightning:card>
</div>
</aura:component>
Log In to reply.