public with sharing class SearchComponent{
@AuraEnabled(cacheable=true)
public static List<Account> getAccountList(String searchKey) {
String key = '%' + searchKey + '%';
return [SELECT Id, Industry, Type, Rating, AnnualRevenue,Website FROM Account WHERE **Type, Rating ,Industry = searchKey** LIMIT 10];
}
}
2 Answers
I am assuming either of Type, Rating or Industry can match with search key then you can write query as below
[SELECT Id, Industry, Type, Rating, AnnualRevenue,Website FROM Account WHERE Type like: searchKey or Rating like: searchKey or Industry like: searchKey LIMIT 10];
What you need is the LIKE operator.
If at least one field should match with the filter, you must put those clauses in OR:
public with sharing class SearchComponent{
@AuraEnabled(cacheable=true)
public static List<Account> getAccountList(String searchKey) {
String key = '%' + searchKey + '%';
return [SELECT Id, Industry, Type, Rating, AnnualRevenue,Website
FROM Account
WHERE Type LIKE :key OR Rating LIKE :key OR Industry LIKE :key
LIMIT 10];
}
}
I would suggest these trailheads: SOQL for Admins and Apex Basics & Database