I have trouble with a component in an Experience site. I'm doing a search bar, which makes a search in the information of two components. It has to show the coincidence or a message like "there's no a coincide". I put the coincidence found in a list so, I'm trying to make a conditional with if but I have an error.
@AuraEnabled
public static List<Beverage__c> showMessage (String searchKey) {
String name = '%' + searchKey + '%';
List <Beverage__c> findCoffee = [SELECT Id, Name, Status__c FROM Beverage__c WHERE Name LIKE :Name AND Type__c = 'Hot'];
List <String> msg = new List <String> {'We do not have this coffee'};
if(findCoffee.isEmpty()) {
return msg;
} else {
return findCoffee;
}
}
And the error says: Illegal conversion from List to List<Beverage__c>
I hope somebody could help me. Thank you :D
I've tried...
public class Result {
@AuraEnabled public List<Beverage__c> beverages { get; set;}
@AuraEnabled public String message { get; set;}
public Result(){
beverages = new List<Beverage__c>();
message = '';
}
}
@AuraEnabled
public static List<Beverage__c> showMessage (String searchKey) {
String name = '%' + searchKey + '%';
List <Beverage__c> findCoffee = [SELECT Id, Name, Status__c FROM Beverage__c WHERE Name LIKE :Name AND Type__c = 'Hot'];
Result r = new Result();
if(findCoffee.isEmpty()) {
r.message = 'We do not have this coffee';
} else {
r.beverages = findCoffee;
}
return r;
}
}
And I got the error Illegal conversion from HotCoffeeListController.Result to List<Beverage__c>
Result
rather than aList<Beverage__c>
, then parse theResult
on the calling end.