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
병훈 송병훈 송 

How is "Lightning Data Service "know which record from "record id"?

How is "Lightning Data Service "know which record from "record id"?
Does "record id" included "record type"?
Code reference only record id, not record type
 
<aura:component implements="flexipage:availableForRecordHome,force:lightningQuickActionWithoutHeader, force:hasRecordId">

    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>

    <force:recordData aura:id="recordLoader"
      recordId="{!v.recordId}"
      layoutType="FULL"
      targetRecord="{!v.record}"
      targetFields="{!v.simpleRecord}"
      targetError="{!v.recordError}"
      recordUpdated="{!c.handleRecordUpdated}"
      />

    <!-- Display a header with details about the record -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.simpleRecord.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
            slds-truncate slds-align-left">{!v.simpleRecord.BillingCity}, {!v.simpleRecord.BillingState}</h1>
    </div>

    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            <ui:message title="Error" severity="error" closable="true">
                {!v.recordError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>


and
Can I skip targetRecord?
Can I just using targetFields?
Best Answer chosen by 병훈 송
Narender Singh(Nads)Narender Singh(Nads)

Hi,

The thing about using Lightning Data Service is that when we are using "force:hasRecordId", the component automatically fetches the recordID of record on whose layout it is on.
Q. Does "record id" included "record type"?
A. No, the record id only contains the recordID of the record but you can perform a SQOL to get the recordtype Id of that record.

Q.Can I skip targetRecord?
Can I just using targetFields?

A. Yes, you can skip the targetrecord, it works. But it isn't considered as a best practice.
targetRecord is populated with the loaded record.
targetFields is populated with the simplified view of the loaded record.

v.targetFields.Name is equivalent to v.targetRecord.fields.Name.value. Therefore for easy dereferencing of object properties we use v.targetfields.

Let me know if this helps.
Thanks! 

All Answers

GhanshyamChoudhariGhanshyamChoudhari
Id sampleid = '00561000000Mjya';
System.debug('object is '+ sampleid.getsobjecttype());

Through the record id, you can find the object and once you know the object name you can extract the fields .


 
Narender Singh(Nads)Narender Singh(Nads)

Hi,

The thing about using Lightning Data Service is that when we are using "force:hasRecordId", the component automatically fetches the recordID of record on whose layout it is on.
Q. Does "record id" included "record type"?
A. No, the record id only contains the recordID of the record but you can perform a SQOL to get the recordtype Id of that record.

Q.Can I skip targetRecord?
Can I just using targetFields?

A. Yes, you can skip the targetrecord, it works. But it isn't considered as a best practice.
targetRecord is populated with the loaded record.
targetFields is populated with the simplified view of the loaded record.

v.targetFields.Name is equivalent to v.targetRecord.fields.Name.value. Therefore for easy dereferencing of object properties we use v.targetfields.

Let me know if this helps.
Thanks! 

This was selected as the best answer