I am trying to make a query that will search for accounts with a name similar or exactly matching a field value.
So for example I have "Sales-Force" in the field. There is an account called "Salesforce" or "Sales Force"
My current query
Select Id, Name FROM Account WHERE Name LIKE '%Sales-Force%'
This isn't returning my accounts named "Sales Force" or "Salesforce" in my query editor.
UPDATED * My Apex code
string accountName= record.Name;
if(accountName.contains('-'))
{
accountName = accountName.replace('-', '%');
}
if(accountName.contains(' '))
{
accountName = accountName.replace(' ', '%');
}
accountName= '%' + accountName+ '%';
List<Account> accountLookup = new List<Account>();
accountLookup = [Select Id, Name FROM Account WHERE Name LIKE :accountName];
Best Answer
Have you considered:
or:
PS
Just noticed Oleksandr had posted this and deleted it: please clarify your question.
PPS
You could add some code that tries to generalize the pattern e.g. replaces non-alphabetic characters with a
%
and puts a%
between each character. Or you could consider e.g. a Metaphone approach to the matching.