-1

Working on the lightning component framework specialist superbadge, stage 6, and getting the following error:

The BoatDetails component must use force:recordData to load the appropriate list of fields from Boat__c into the boat attribute of the component.

I'm using the requested application event 'BoatSelected' to pass the boat attribute from BoatTile to BoatDetails. I'm able to retrieve the parameter from the event and set the value of the 'id' attribute using the passed in value. However, after telling the force:recordData to reloadRecord the attribute used in targetFields is still null.

Do I need to be using a server side controller to fetch the data, or should I be doing something with the callback function on the reloadData call maybe? Really thought this was supposed to be baked in functionality.

BoatDetailsController.js

onBoatSelected : function(component, event, helper) {
    console.log('onBoatSelected');
    var boat = event.getParam("boat");



    component.set("v.id",boat.Id);
    component.find("service").reloadRecord();
    var newBoat = component.get("v.boat");
    console.log('get v.id: '+component.get("v.id"));<--logs proper Id
    console.log('newBoat: '+newBoat);<-- shows as null in logs
    console.log('newBoat.Id: '+newBoat.Id);<-- throws null pointer error
}

BoatDetails.cmp

<aura:component implements="flexipage:availableForAllPageTypes">

<aura:attribute name="boat" type="Boat__c" access="public"/>
<aura:attribute name="id" type="Id" access="public"/>
<aura:attribute name="serviceError" type="String"/>
<aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}"/>
<force:recordData aura:id="service"
                  recordId="{!v.id}"
                  mode="VIEW"
                  targetFields="{!v.boat}"
                  fields="Id,
                          Name,
                          Description__c,
                          Price__c,
                          Length__c,
                          Contact__r.Name,
                          Contact__r.Email,
                          Contact__r.HomePhone,
                          BoatType__r.Name,
                          Picutre__c"
                  targetError="{!v.serviceError}"
                  recordUpdated="{!c.onRecordUpdated}"/>
<aura:if isTrue="{!not(empty(v.boat))}">
    <lightning:tabset>
        <lightning:tab label="Details">
            <c:BoatDetail boat="{!v.boat}"/>
        </lightning:tab>
        <lightning:tab label="Reviews">

        </lightning:tab>
        <lightning:tab label="Add Review">

        </lightning:tab>
    </lightning:tabset>
</aura:if>

BoatSelected.evt

<aura:event type="APPLICATION" description="fires when a user clicks a boat on BoatSearchResults.cmp">
<aura:attribute name="boat" type="Boat__c"/>
</aura:event>

BoatTileController.js

onBoatClick : function(component, event, helper) {
    console.log('onBoatClick');
    var clickEvent = component.getEvent("BoatSelect");
    var showBoatDetails = $A.get("e.c:BoatSelected");
    showBoatDetails.setParam("boat",component.get("v.boat"));
    clickEvent.setParam("boatId", component.get("v.boat.Id"));
    showBoatDetails.fire();
    clickEvent.fire();

}
3

The field name of Picture__c has incorrect spelling in the tag - force:recordData

It is currently

force:recordData aura:id="service"
                  recordId="{!v.id}"
                  mode="VIEW"
                  targetFields="{!v.boat}"
                  fields="Id,
                          Name,
                          Description__c,
                          Price__c,
                          Length__c,
                          Contact__r.Name,
                          Contact__r.Email,
                          Contact__r.HomePhone,
                          BoatType__r.Name,
                          Picutre__c"
                  targetError="{!v.serviceError}"
                  recordUpdated="{!c.onRecordUpdated}"/>

It should be

force:recordData aura:id="service"
                  recordId="{!v.id}"
                  mode="VIEW"
                  targetFields="{!v.boat}"
                  fields="Id,
                          Name,
                          Description__c,
                          Price__c,
                          Length__c,
                          Contact__r.Name,
                          Contact__r.Email,
                          Contact__r.HomePhone,
                          BoatType__r.Name,
                          Picture__c"
                  targetError="{!v.serviceError}"
                  recordUpdated="{!c.onRecordUpdated}"/>
1
  • I forgot I hadn't closed this. I eventually found it, though it took me a few(waaay) too many hours... Thank you.
    – SFDC Noob
    Aug 28 '18 at 21:25

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.