2

I am testing out the LDS feature in Summer 17 Preview org. I have created a component and put it on the account detail page. Component has LDS to fetch the data and some markup to display the fetched data. But nothing shows up.

Code :

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="record" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="recordLoader"
                  recordId="{!v.recordId}"
                  layoutType="FULL"
                  targetRecord="{!v.record}"
                  targetError="{!v.recordError}"
                  />
{!v.record.Name}
{!v.record.BillingCity}

<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>

Could someone please help with this.

  • Try adding in targetFields="{!v._fieldsToQuery}" and specify fieldsToQuery as string[] attribute and see if the data shows up – Rao Apr 25 '17 at 16:56
  • @Rao, Are you sure that it is a string[] attribute. I am confused if it is a string[] attribute or an object attribute as the documentation says it is a simplified view of the fields. I thought it will be in the form of key value pair. – Nihar Apr 25 '17 at 17:01
  • You may be right. Take a look at youtube.com/watch?v=2oOthaxzYhE Look at 13:12, I attended this meetup and got a preview. what they have there is not the final . The name fields is what I think ended up as targetfields. when you look at targetfields shape. I @14.08 it shows up as key value pair. I do not have a summer 17 preview org so cant really test the recorddata feature yet – Rao Apr 25 '17 at 17:06
  • @Rao, Nihar, the targetFields attribute is indeed an object with field names as keys, to give you simplified access to field values in component markup without typing out all the "record.fields.FieldName.value" boilerplate. (Setting it to "{!v._fieldsToQuery}" is being updated in the docs, since you're right, that was misleading.) – Carolyn Grabill May 4 '17 at 1:01
6

I was able to display the data on the component with slight modifications. In summer 17 release the structure of the retrieved record using data service is slightly modified and also a new tag has been introduced to make accessing the data simpler. The new structure of data and the new tag introduced are available at this link : https://releasenotes.docs.salesforce.com/en-us/summer17/release-notes/rn_lightning_data_service.htm

There is also a video(from 14 min to 17 min) explaining the use of new tag : https://www.youtube.com/watch?v=2oOthaxzYhE

Modified code looks like:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" 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.BillingCity}

<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>

force:recordData has a new attribute "target fields" which makes it simpler to access data. The value assigned to target fields(fieldstoQuery) is of type object and it is a more simplified way to access data according to the release notes.

  • I assume you are using a client side controller to populate the value of targertFields attribute? can you post your controller too? – Rao Apr 25 '17 at 17:35
  • 2
    No Client side controller is necessary. Just the component markup is enough. I am assuming that all the data that is available on the page layout (as I am giving layoutType= FULL)is loaded into fieldsToQuery(can be any name) attribute once the framework encounters the force:recordData tag and the data can be directly accessed using that attribute and the corresponding field name. – Nihar Apr 25 '17 at 17:40
  • ah yes I remember now, depending on the layout type the fields are rendered. – Rao Apr 25 '17 at 17:42
  • 1
    **One thing that does not seem to work is that if I have an init handler(which is automatically invoked by the framework when component is loaded) the handler action does not seem to have the data from fieldsToquery yet. I think this is because the framework is invoking the handler action before loading the data using LightningDataService. – Nihar Apr 25 '17 at 17:47
  • Question (might be available in documentation, but I'd prefer to get real world answer from people using LDS): Does force:recordData actually display data, or just provide a mechanism for retrieving and storing a record and you display the data using other tags/mechanisms? – Florissant53 Apr 25 '17 at 18:23
3

The shape of targetRecord changed compared to the developer preview. You can use targetFields instead if you want the simplified record view, or you can change your targetRecord references to match the new shape:

{!v.record.fields.Name.value}
{!v.record.fields.BillingCity.value}

targetRecord has a lot more properties than it did in the preview, such as display values and record type info, so the data shape has more object levels now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.