While doing the super badge "Lightning Component Framework Specialist" I get the Internal Server error.
here is the code snippet.
BoatSearchResults.apxc
public with sharing class BoatSearchResults {
@AuraEnabled
public static List<Boat__c> getBoats(String boatTypeID) {
System.debug('BoatSearch Results : ' + boatTypeID);
List<Boat__c> returnList;
if (boatTypeID != ''){
returnList = [Select ID, Name, BoatType__c, contact__r.Name, Geolocation__c, Picture__c from Boat__c
where BoatType__c =:boatTypeID];
} else {
returnList = [Select ID, Name, BoatType__c, contact__r.Name, Geolocation__c, Picture__c from Boat__c];
}
System.debug('BoatSearch Results Return Count: ' + returnList.size());
return returnList;
}
}
BoatSearchResultsHelper.js
({
onSearch : function(component) {
// Create the action
var boatTypeID = component.get('v.selectedBoatID');
console.log('In onSearch function: ' + boatTypeID);
var action = component.get("c.getBoats");
action.setParams({boatTypeID : boatTypeID});
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
console.log('In onSearch function state: ' + state);
if (state === "SUCCESS") {
component.set("v.boats", response.getReturnValue());
}
else {
console.log('In onSearch function Failed: ' + response);
console.info('RESPONSE', response);
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("***Error message: " +
errors[0].message);
}
} else {
console.log("***Unknown error");
}
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})
BoatSearchResults.cmp
<aura:component implements="flexipage:availableForAllPageTypes" controller="BoatSearchResults">
<aura:handler name="boatSelect" event="c:BoatSelect" action="{!c.handleBoatSelect}"/>
<aura:method name="search"
description="Method to search all boats related to boat type">
<aura:attribute name="boatTypeId" type="String" />
</aura:method>
<aura:attribute name="selectedBoatID" type="String"/>
<aura:attribute name="boats" type="Boat__c[]" default="[]"/>
<lightning:layout horizontalAlign="space" multipleRows="true">
<aura:if isTrue="{!not(empty(v.boats))}">
<!--Iterate the mapEntry Component.-->
<aura:iteration items="{!v.boats}" var="boat" >
<lightning:layoutItem flexibility="auto" size="12" mediumDeviceSize="6" largeDeviceSize="3" padding="around-small">
<c:BoatTile boat="{!boat}" selected="false"/>
</lightning:layoutItem>
</aura:iteration>
<aura:set attribute="else">
<div class="slds-align_absolute-center" style="text-align:center;"> No boats found </div>
</aura:set>
</aura:if>
</lightning:layout>
</aura:component>
Strangely I did clear the step 4 “Implement the search filter” even with this error. However I want this to be resolved so that I can go ahead with other steps.
Any help will be appreciated .
lightning:layout
and see if the error goes away. I think it has to do with how you uselightning:layoutItem
. let us know.SELECT Id, Name,Contact__r.name FROM Boat__c where BoatType__r.Name=:boatTypeId
. When you cleared challenge 4 , did you see the boats appearing on the page, if not something is breaking in other components may be - BoatSearch / BoatSearchForm. Also I used the content of your markupBoatSearchResults
( the content fromlightning:layout
) and it did not allow me to save the cmp. It showed some error. Not sure how you got it saved.