• Biswajit Samantaray
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true"/>
    <p><ui:outputText value="{!v.item.Name}"/></p>
    <p><ui:outputCurrency value="{!v.item.Price__c}"/></p>
    <p><ui:outputNumber value="{!v.item.Quantity__c}"/></p>
    <p><ui:outputCheckbox value="{!v.item.Packed__c}"/></p>
</aura:component>
Cross-posting here from the Trailhead forum, where I'm working on the Lightning Components Framework SuperBadge. We're implementing LDS on a page, but NOT using force:hasRecordId. Instead, we're dynamically setting an aura:attribute, and then referencing it in the LDS parameter for recordId. I've been researching this for hours, but all the reference docs and Trailhead modules assume the case where you're using the implicit recordId on the page. No examples I can find where they're setting the recordId and then forcing the reload.

In this case, the id attribute is successfully being set, but LDS isn't loading the record. The error message says: The onBoatSelected handler in the BoatDetails controller must force Lightning Data Service to load the specified record, using logic in the controller.

In the controller, I'm using a reloadRecord command: component.find("service").reloadRecord() where "service" is the aura:id for the force:recordData element.

Is there some other command required to get the LDS to load the record?

Here's the component markup with the force:recordData info:
<aura:attribute name="id" type="String"/>
    <aura:attribute name="boat" type="Boat__c"/>
    <aura:attribute name="boatSimple" type="Boat__c"/>
    <aura:attribute name="recordError" type="String"/>

    <aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}"/>

    <force:recordData aura:id="service"
                      recordId="{!v.id}"
                      mode="VIEW"
                      fields=  "Id,
                                Name,
                                Description__c,
                                Price__c, Length__c,
                                Contact__r.Name,
                                Contact__r.Email,
                                Contact__r.HomePhone,
                                BoatType__r.Name,
                                Picture__c"
                      targetRecord="{!v.boat}"
                      targetFields="{!v.boatSimple}"
                      targetError="{!v.recordError}"
                      recordUpdated="{!c.onRecordUpdated}" />
Am I screwing up something in the markup? 

 
Re-factored my code from previous units with base lightning components, but receiving this error.  Here's my new form component.  Any help would be much appreciated.

<aura:component >   
    <aura:attribute name="newItem" type="Camping_Item__c"    default="{ 'sobjectType': 'Camping_Item__c',
                         'Name': '',
                         'Price__c': 0,
                         'Quantity__c': 0,                         
                         'Packed__c': false
                       }"/>
 
    <aura:registerEvent name="addItem" type="c:addItemEvent"/>
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">
<div aria-labelledby="newItemForm">

    <!-- BOXED AREA -->
    <fieldset class="slds-box slds-theme--default slds-container--small">

    <legend id="newItemForm" class="slds-text-heading--small 
      slds-p-vertical--medium">
      Add Camping Item
    </legend>

    <!-- CREATE NEW CAMPING ITEM FORM -->
    <form class="slds-form--stacked">          
        <lightning:input aura:id="itemForm" label="Camping Item Name"
                         name="Name"
                         value="{!v.newItem.Name}"
                         required="true"/> 
        <lightning:input type="number" aura:id="itemForm" label="Quantity"
                         name="Quantity"
                         maxlength="16"
                         min="0"
                         step="1"
                         value="{!v.newItem.Quantity__c}"
                         required="true"/>
        <lightning:input type="number" aura:id="itemForm" label="Price"
                         name="Price"
                         min="0"
                         step=".01"
                         value="{!v.newItem.Price__c}"
                         formatter="currency"
                         messageWhenRangeUnderflow="Enter an amount that's at least .01."/>
        <lightning:input type="checkbox" aura:id="itemForm" label="Packed?"  
                         name="Packed"
                         checked="{!v.newItem.Packed__c}"/>
        <lightning:button label="Create Expense" 
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreateItem}"/>
    </form>
  </fieldset>
  <!-- / BOXED AREA -->

</div>
        </lightning:layoutItem>
    </lightning:layout>
</aura:component>