I am trying to return the account records on the basis of some search keywords like AccountName, Billing Street, BillingState, BillingCity and PostalCode. I am able to return the results but not able to filter the accounts with the combination of multiple keywords. e.g. if there are three accounts in system as below:
Name BillingState BillingCity PostalCode
1. Test1 Alaska Anchorage 99501
2. Test2 Arizona Phoenix 85001
3. Test1 Arkansas LittleRock 72201
If i enter in keywords as Test in AccountName and Phoenix in BillingCity, it returns all the three accounts but the expectation is it should return only Test2 record.
@auraEnabled
public static List <Account> fetchAccountRecords(String searchKeyWord, String searchKeyWord1, String
searchKeyWord2, String searchKeyWord3, String searchKeyWord4) {
String searchkey = '%' + searchKeyWord + '%';
String searchkey1 = '%' + searchKeyWord1 + '%';
String searchkey2 = '%' + searchKeyWord2 + '%';
String searchkey3 = '%' + searchKeyWord3 + '%';
String searchkey4 = '%' + searchKeyWord4 + '%';
List < Account > lstOfAccount =
[Selectid,Name,BillingStreet,Type,BillingCity,BillingState,BillingPostalCode,
RecordType.Name,Territory__r.Name from Account where (Name LIKE: searchkey
OR BillingStreet LIKE: searchkey1 OR BillingCity LIKE: searchkey2 OR
BillingState LIKE: searchKey3 OR BillingPostalCode LIKE: searchkey4)];
return lstOfAccount;
}