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
Francesca Ribezzi 2Francesca Ribezzi 2 

Lightning Component Framework Specialist SuperBadge - Step 5-6

Hi everyone,
I'm getting this error at Step 6: "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 believe it's because my "auraMethodResult" happens to be undefined for some reason.. Can anyone help me with this, please? Thank you so much :-)
BoatSearch:
<aura:handler name="formsubmit" event="c:FormSubmit" action="{!c.onFormSubmit}"  phase="capture"/>
   
 
    <div>
    <lightning:card class="findBoatCard" title="Find a Boat">
        <c:BoatSearchForm />    
    </lightning:card>     
    </div>
    
    <lightning:card title="Matching Boats">
        <c:BoatSearchResults aura:id="child"/>
    </lightning:card>
</aura:component>


BoatSearchController:
({

    onFormSubmit : function(component, event, helper){
 
        var formData = event.getParam("formData");
        var boatTypeId = formData.boatTypeId;
        var child = component.find("child");
        var auraMethodResult = child.search(boatTypeId);
        console.log("auraMethodResult: " + auraMethodResult);
    },

})

BoatSearchResults:
 	<aura:attribute name="boat" type="BoatType__c"/> 
    <aura:attribute name="boats" type="Boat__c[]"/> 
    <aura:attribute name="selectedBoatId" type="Object"/> 
    
<aura:handler name="boatClickEvent" event="c:BoatSelect" action="{!c.onBoatSelect}" />

    <aura:method name="search" action="{!c.doSearch}"> 
        <aura:attribute name="boatTypeId" type="Object" /> 
    </aura:method>
    
<lightning:layout multipleRows="true" horizontalAlign="center">

    <aura:iteration items="{!v.boats}" var="boat"> 
        <lightning:layoutItem   flexibility="grow" class="slds-m-right_small" >   
        
                <c:BoatTile boat="{!boat}" selected="{! boat.Id == v.selectedBoatId ? true : false }"/> 
            
        </lightning:layoutItem>
    </aura:iteration>

    
    <aura:if isTrue="{! empty(v.boats)}"> 
        <lightning:layoutItem class="slds-align_absolute-center" flexibility="auto" padding="around-small">   
            <ui:outputText value="No boats found" />
        </lightning:layoutItem>
 
    </aura:if>
    
    </lightning:layout>

BoatSearchResultsController:
({
	doSearch : function(component, event, helper) {
      
        var params = event.getParam('arguments');
        
        component.set("v.boatTypeId", params.boatTypeId);
        helper.onSearch(component);
     
    },
    
    onBoatSelect: function(component, event, helper){
        var selectedBoatId = event.getParam('boatId');
        component.set("v.selectedBoatId", selectedBoatId);
    }
})
 
BoatTile
	<aura:attribute name="boat" type="Boat__c"/> 
    <aura:attribute name="selected" type="Boolean" default="false"/> 

      <aura:registerEvent name="boatClickEvent" type="c:BoatSelect"/>
     <aura:registerEvent name="boatSelected" type="c:BoatSelected"/>
    

    
    <lightning:button aura:id="boatTileButton" class="{!v.selected == 'true' ? 'tile selected' : 'tile'}" onclick="{!c.onBoatClick}">
        <div style="{! 'background-image:url(\'' + v.boat.Picture__c + '\'); '}" class="innertile">
            
            <div class="lower-third">
                <h1 class="slds-truncate">{!v.boat.Contact__r.Name}</h1>

            </div>
        </div>
    </lightning:button>  
BoatTileController:

({
    onBoatClick : function(component, event, helper) {
      
       var boatType = component.get("v.boat");
        console.log('Boat asd'+boatType);
        var boatSelectEvt = component.getEvent("boatClickEvent");
        boatSelectEvt.setParams({"boatId" :boatType.Id});
        boatSelectEvt.fire();
        
 
        var appEvent = $A.get("e.c:BoatSelected");
        var boat = component.get("v.boat");  
        appEvent.setParams({
            "boat": boat
        });
        appEvent.fire();    
     }
})

 
Shubham saini 14Shubham saini 14
Hi Francesca,
 
/** BoatDetails.cmp **/

<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="boat" type="Boat__c" />
    <aura:attribute name="id" type="Id" />
    <aura:attribute name="simpleRecord" type="Object" />
    <aura:attribute name="recordError" type="String" />
    <aura:attribute name="selTabId" type="String" />
    <aura:handler event="c:BoatSelected" action="{!c.onBoatSelected}" />
    <aura:handler name="BoatReviewAdded" event="c:BoatReviewAdded" action="{!c.onBoatReviewAdded}" />
    <force:recordData aura:id="service"
      recordId="{!v.id}"
      fields="Id,
              Name,
              Description__c,
              Price__c,
              Length__c,
              Contact__r.Name,
              Contact__r.Email,
              Contact__r.HomePhone,
              BoatType__r.Name,
              Picture__c"
      mode="VIEW"
      targetRecord="{!v.boat}"
      targetFields="{!v.simpleRecord}"
      targetError="{!v.recordError}"
      recordUpdated="{!c.onRecordUpdated}"
      />
    <aura:if isTrue="{! !empty(v.boat)}">
        <lightning:tabset aura:id="tabs" selectedTabId="{!v.selTabId}">
            <lightning:tab label="Details" id="Details">
                <c:BoatDetail boat="{!v.simpleRecord}" />
            </lightning:tab>
            <lightning:tab label="Reviews" id="boatreviewtab">
                <c:BoatReviews boat="{!v.boat}" aura:id="BR" />
            </lightning:tab>
            <lightning:tab label="Add Review" id="addReview">
                <c:AddBoatReview boat="{!v.boat}" aura:id="ABR" />
            </lightning:tab>
        </lightning:tabset>    
    </aura:if>
</aura:component>
 
/** BoatDetailsController.js **/

({
	onBoatSelected : function(component, event, helper) {
		var boatEvt = event.getParam("boatEvt");
        component.set("v.id",boatEvt.Id);
        component.find("service").reloadRecord();
	},
    onRecordUpdated : function(component, event, helper) {
        var ABRcmp = component.find('BR');
        //var auraMethodResult = ABRcmp.refresh();
	},
    onBoatReviewAdded : function(component, event, helper) {
        component.find("tabs").set("v.selectedTabId", "boatreviewtab");
        var ABRcmp = component.find('BR');
        //var auraMethodResult = ABRcmp.refresh();
	},
})

I hope it will help you