0
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 2

0

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];
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .