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
Neerudu PriyankaNeerudu Priyanka 

ightning Component Framework Specialist SuperBadge Issue at Step 3.

<aura:component controller="BoatSearchResults">
    
    <aura:handler name="init" action="{!c.doSearch}" value="{!this}"/>
	<aura:attribute name="boats" type="Boat__c[]" />

 <lightning:layout horizontalAlign="center" verticalAlign="center">
            <lightning:layoutItem flexibility="grow"  class="slds-m-right_small" >   
    			<aura:iteration items="{!v.boats}" var="boatVar">
                	<c:BoatTile boat="{!boatVar}"/>
                </aura:iteration>
    		
               
                <aura:renderIf isTrue="{!v.boats.length==1}">
                    <div style="margin-left: 50%;">
                    <ui:outputText value="No boats found" />
                        </div>
                </aura:renderIf>
     </lightning:layoutItem>
    </lightning:layout>
</aura:component>
 
({
    onSearch : function(component, event, helper) {
        console.log('In Helper');
        var action=component.get('c.getBoats');
         action.setParam({"boatTypeId":''});
        action.setCallback(this,function(response) {
            if(response.getState() === 'SUCCESS')
            {
                var boatslist = response.getReturnValue();
                component.set("v.boats",boatslist);
            }
        });
        $A.enqueueAction(action);
    }
})
 
({
    doSearch: function(component, event, helper) {
          helper.onSearch(cmp);
    }
})
 
public with sharing class BoatSearchResults {

    @Auraenabled
    public static List<Boat__c> getBoats(String boatTypeId)
    {
       if(boatTypeId != '')
       {
       return ([Select Id,Name, BoatType__c , Contact__r.Name , Description__c,Geolocation__c,Length__c,Price__c,Year_Built__c
               from Boat__c Where Id = :boatTypeId]); 
       }
       else
       {
           return ([SELECT Id, BoatType__c, picture__c, name,contact__r.Name from Boat__c]);
       }
    }
}

 
Best Answer chosen by Neerudu Priyanka
NagendraNagendra (Salesforce Developers) 
Hi Priyanka,

Sorry for this issue you are facing.

I would suggest you do a few modifications to your code.

BoatSearchResultsController.js
({
    doSearch : function(component, event, helper) {
        component.get("v.boatTypeId");
        helper.onSearch(component, event, helper);
    },
   })
BoatSearchResultsHelper.js
({
    onSearch : function(component, event, helper) {
        var boatTypId = component.get("v.boatTypeId");
        console.log("boatTypId--> " + boatTypId);
        // create an action
        var action = component.get("c.getBoats");
        action.setParams({boatTypeId:boatTypId});
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state == "SUCCESS") {
                console.log("response.getReturnValue() " + response.getReturnValue());
                component.set("v.boats", response.getReturnValue());
            } else {
                console.log("Failed with state: " + state);
            }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    }
})
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra


 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Priyanka,

Sorry for this issue you are facing.

I would suggest you do a few modifications to your code.

BoatSearchResultsController.js
({
    doSearch : function(component, event, helper) {
        component.get("v.boatTypeId");
        helper.onSearch(component, event, helper);
    },
   })
BoatSearchResultsHelper.js
({
    onSearch : function(component, event, helper) {
        var boatTypId = component.get("v.boatTypeId");
        console.log("boatTypId--> " + boatTypId);
        // create an action
        var action = component.get("c.getBoats");
        action.setParams({boatTypeId:boatTypId});
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state == "SUCCESS") {
                console.log("response.getReturnValue() " + response.getReturnValue());
                component.set("v.boats", response.getReturnValue());
            } else {
                console.log("Failed with state: " + state);
            }
        });
        // Send action off to be executed
        $A.enqueueAction(action);
    }
})
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra


 
This was selected as the best answer
Raj VakatiRaj Vakati
Use this code

https://salesforceallinone.blogspot.com/2018/03/lightning-component-framework_87.html
 
<aura:component controller="BoatSearchResults">

    <aura:handler name="init" action="{!c.doSearch}" value="{!this}"/>
 <aura:attribute name="boats" type="Boat__c[]" />

 <lightning:layout horizontalAlign="center" verticalAlign="center" multipleRows='true'>
            <lightning:layoutItem flexibility="grow"  class="slds-m-right_small" >
     <aura:iteration items="{!v.boats}" var="boatVar">
                 <c:BoatTile boat="{!boatVar}"/>
                </aura:iteration>
      <aura:if isTrue="{!v.boats.length > 0}">
                <aura:iteration items="{!v.boats}" var="bot">
                    <lightning:layoutItem flexibility="grow" class="slds-m-around_small">
                        <c:BoatTile boat="{!bot}" />
                    </lightning:layoutItem>
                </aura:iteration>
                <aura:set attribute="else">
                    <lightning:layoutItem class="slds-align_absolute-center" flexibility="auto" padding="around-small">
                        <ui:outputText value="No boats found" />
                    </lightning:layoutItem>
                </aura:set>
            </aura:if>


     </lightning:layoutItem>
    </lightning:layout>
</aura:component>
 
({
 doSearch : function(component, event, helper) {
  alert(component.get("v.boatTypeId")); //<---here I am getting undefined
        helper.onSearch(component); //calling helper method
 },
     search: function(component, event, helper){
        var params = event.getParam('arguments');
        alert(params.boatTypeId); //<---getting proper value
        alert(component.set("v.boatTypeId", params.boatTypeId)); //<---here I am getting undefined
        var a = component.get('c.doSearch');
        $A.enqueueAction(a);
    }
})
 
({
    onSearch : function(component, event) {
        var boatTypId = component.get("v.boatTypeId");
        alert(boatTypId); //<---here I am getting undefined
        console.log("boatTypId--> " + boatTypId);
        var action = component.get("c.getBoats");
        action.setParams({boatTypeId:boatTypId});

        //add the callback behavior for when the response is received
        action.setCallback(this, function(response){
            var state = response.getState();
            console.log("state " + state);
            if(state === "SUCCESS"){
                var res = response.getReturnValue();
                component.set("v.boats", res);
                //console.log("v.boats ->"+ JSON.stringify(res));
            }
            else{
                console.log("Failed with state: " + state);
            }
        });

        //send action off to be executed
        $A.enqueueAction(action);
    },
})