You need to sign in to do that
Don't have an account?
chaitanya motupalli 13
missing return statement required return type
Hi I have written below apex method for LWC but i am getting "missing return statement required return type" error when trying to deploy to org.
please help me where i am doing wrong here.
public with sharing class bikeSearchResultController {
@AuraEnabled(cacheable=true)
public static list<Car__c> cardetailsapexmethod(string cartypeid){
try {
if(String.isEmpty(cartypeid)){
return [SELECT Id,Available_For_Rent__c,Build_Year__c,Car_Type__c,Name,Picture__c
FROM Car__c];
}else
if(!String.isEmpty(cartypeid)){
return [SELECT Id,Available_For_Rent__c,Build_Year__c,Car_Type__c,Name,Picture__c
FROM Car__c
WHERE Car_Type__c=:cartypeid];
}
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
}
}
please help me where i am doing wrong here.
public with sharing class bikeSearchResultController {
@AuraEnabled(cacheable=true)
public static list<Car__c> cardetailsapexmethod(string cartypeid){
try {
if(String.isEmpty(cartypeid)){
return [SELECT Id,Available_For_Rent__c,Build_Year__c,Car_Type__c,Name,Picture__c
FROM Car__c];
}else
if(!String.isEmpty(cartypeid)){
return [SELECT Id,Available_For_Rent__c,Build_Year__c,Car_Type__c,Name,Picture__c
FROM Car__c
WHERE Car_Type__c=:cartypeid];
}
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
}
}
Try the below changes:
Thanks,
Maharajan.C
All Answers
Can you try if you are able to return after assigning the response of the soql to a list variable and returning the list variable like changing the above code to below:
Looking forward to your response.
Thanks.
Try the below changes:
Thanks,
Maharajan.C