function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Devon FritzDevon Fritz 

Is there a way to have a query include custom matches?

We're using a matching rule for Accounts (aka 'companies') on SF that basically says 'If a company has both the "same name" and an identical company number, consider them duplicates' and a duplicate rule that prevents said duplicates from being created. 

'Same name' uses SF's `FUZZY: COMPANY NAME` logic, which means on creation it's smart enough to recognise eg `Microsoft Inc.` as the same company as `Microsoft` if they share a number.

Unfortunately for us, the SOQL queries don't have the same intelligence - if I run the query "select Id from Account where Name = 'Microsoft'", and I have a company with the name `Microsoft Inc.` I find no results.

Is there a built-in way to do a 'fuzzy search', so that we find any record(s) that would be considered a match according to our matching rules?

Thanks all.
Ronty AhmadRonty Ahmad
HI Devon

You can try to use LIKE with % wild card  insted of (=) for example.
select Id,name from Account where Name LIKE '%burlington%' or Name LIKE '%America%' and ..

select Id,name from Account where Name LIKE '%Microsoft%'  and/or ....

You can more about like on following url

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_where.htm

Expression is true if the value in the specified fieldName matches the characters of the text string in the specified value. The LIKE operator in SOQL and SOSL is similar to the LIKE operator in SQL; it provides a mechanism for matching partial text strings and includes support for wildcards.
The % and _ wildcards are supported for the LIKE operator.
The % wildcard matches zero or more characters.
The _ wildcard matches exactly one character.
The text string in the specified value must be enclosed in single quotes.
The LIKE operator is supported for string fields only.
The LIKE operator performs a case-insensitive match, unlike the case-sensitive matching in SQL.
The LIKE operator in SOQL and SOSL supports escaping of special characters % or _.
Don’t use the backslash character in a search except to escape a special character.
For example, the following query matches Appleton, Apple, and Appl, but not Bappl:
SELECT AccountId, FirstName, lastname
FROM Contact
WHERE lastname LIKE 'appl%'

Thanks

Ronty