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
Jassi Johal 7Jassi Johal 7 

Lightning Component Superbadge - Issue with Step 3

Challenge Not yet complete... here's what's wrong: 
The getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.

getting this error
Jassi Johal 7Jassi Johal 7
public with sharing class BoatSearchResults  {
    @AuraEnabled
    public static List<Boat__c> getBoats(String boatTypeId) {
      if(boatTypeId != '')  {
             return [SELECT id, BoatType__c, picture__c, name,contact__r.Name
                    FROM Boat__c
                    WHERE BoatType__c =:boatTypeId];
      } else {
          return [SELECT id, BoatType__c, picture__c, name,contact__r.Name
                    FROM Boat__c];
      }
         }
         }

 
Prem Rai 38Prem Rai 38
Hi,
I'm getting same error with same code. Were u able to find any resolution? Can you help me out, please?
kumar1.3974943853885857E12kumar1.3974943853885857E12
Hi,
Anyone able to figure out what should be doing while encountering the error. 
I am also still stuck at Step3, I am getting below error:

Challenge Not yet complete... here's what's wrong: 
The
getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.

Please, someone, tell what I should do.

Thanks - Naresh
Sana nikileshSana nikilesh
HI,

I'm struck at Step3, below is the following error:

Challenge Not yet complete... here's what's wrong: 
The getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.

BoatSearchResults

public with sharing class BoatSearchResults {

    @AuraEnabled
    public static List<Boat__c> getBoats(String boatTypeId) {
        List<Boat__c> boats = new List<Boat__c>();
        if (String.isEmpty(boatTypeId)) {
            boats = [select Id,Name,Picture__c,Contact__r.name from Boat__c];
        } else{
            boats = [select Id,Name,Picture__c,Contact__r.name from Boat__c where BoatType__c = :boatTypeId ];
        }
        
        return boats;
    }
}


Can someone help me out please ?

 
yogesh_patilyogesh_patil
Use String.isEmpty() to check if the boatTypeId  is not null/empty.
Satyajeet JaragSatyajeet Jarag
All of you are getting Error for this challenge because data is not created in your org and assertion is getting failed. 
when you click on button Check Challange if you see in debug logs one log will get generated for your challenge and you will get AssertionException like System.AssertException: Assertion Failed: Boats found due to no data found.

So for this, you have to first run one method in Anonymous block which will create data for you in your org and then try again to check challenge. see below.

User-added image 

Mark this as Best Answer if your issues get resloved with this...!
raghu narayanaraghu narayana
@satyajeet -Thanks
Diego VargasDiego Vargas
 public static List<Boat__c> getBoats(String boatTypeId){  
        String queryTemplate = 'SELECT Name,Id, Contact__c, Picture__c FROM Boat__c {0} {1}';
        List<String> whereClauses = new List<String>();
        if(String.isNotBlank(boatTypeId)){
            whereClauses.add('BoatType__c =:boatTypeId');
        }
        return Database.query(
                                  String.format(queryTemplate, new List<String> { whereClauses.size() > 0 ? 'WHERE' : '', String.join(whereClauses, ' OR ') }));
    }
player00198player00198
thank you @satyajeet it worked 
Raju Cherukuri 24Raju Cherukuri 24
Even after runnign GenerateData.initData() I am getting same error in my log System.AssertException: Assertion Failed: Boats found
 
Mohammad Shahid ShahMohammad Shahid Shah
HI,

I'm struck at Step3, below is the following error:

Challenge Not yet complete... here's what's wrong: 
The getBoats() method isn't working properly. Define getBoats() In the BoatSearchResults Apex controller to accept an optional boatTypeId and return all boats if no boatTypeId is passed, and a filtered list of boats if a boatTypeId is passed.

BoatSearchResults.apxc

public with sharing class BoatSearchResults  { 
@AuraEnabled    
public static List <Boat__c> getBoats(String boatTypeId) {    
if(boatTypeId != '')  {         
return [SELECT id, BoatType__c, picture__c, name,contact__r.Name FROM Boat__c WHERE BoatType__c =:boatTypeId];    
} else {       
return [SELECT id, BoatType__c, picture__c, name,contact__r.Name FROM Boat__c];    
}      
}    

}
Can someone help me out ??
Swaminathan ESwaminathan E
Hi,
Please write the code like these
 @AuraEnabled(cacheable=true)  public static List<Boat__c> getBoats(String boatTypeId) {..}
@AuraEnabled(cacheable=true) public static List<Boat__c> getSimilarBoats(Id boatId, String similarBy) {..}
@AuraEnabled(cacheable=true) public static List<BoatType__c> getBoatTypes() {..}
 @AuraEnabled(cacheable=false) public static List<BoatReview__c> getAllReviews(Id boatId) {..}
 @AuraEnabled(cacheable=true) public static String getBoatsByLocation(Decimal latitude, Decimal longitude, String boatTypeId) {..}
 @AuraEnabled(cacheable=true)  public static String updateBoatList(Object data){..}

     if it worked, choose the Best Answer.
subhadeep maitisubhadeep maiti
make all your apex methods as @AuraEnabled(cacheable=true) except getAllReviews (make it only @AuraEnabled )

Thanks,
Subhadeep
JeffreyStevensJeffreyStevens
FYI - Removing the cacheable from the GetAllReviews method worked for me.
Praseeda Menon 10Praseeda Menon 10
Any thoughts on why did we make getAllReviews() to be non cacheable?