I'm working on a query to find some duplicate records by name. I take the name and replace anything thats not a letter with a wildcard. I wind up with a query that looks like this:


I've got a few duplicate records in the sandbox:

Account(Name = 'Name4Name')
Account(Name = 'Name four Name')
Account(Name = 'Name4Name Name')

However, only "Name4Name" & "Name4Name Name" is returned as a query result.

The documentation says:

Use an asterisk (*) to find items that match zero or more characters at the middle or end of your query.

Use a question mark (?) to find items that match only one character at the middle or end of your query.

From this, I would expect all names to be returned in the query, but only the first & last ones are returned. I'm a bit stumped here - how can I get all of these records to return? Why does only one value return in the first place?

Looks like this query runs fine:

SELECT Id, Name FROM Account WHERE Name LIKE '%NAME%Name%'

Pretty weird that SOQL works fine where SOSL fails. Will post as answer later but would be interested in hearing why these two queries are different.

  • 1
    You mean SOSL and not SOQL, right? – David Cheng Sep 5 '19 at 14:24
  • Yes - thank you! – battery.cord Sep 5 '19 at 14:28

This seems like unexplainable bug. When there is exactly 1 word between 2 names like name someWord name someOtherWord, it does not return the record. However, if you add spaces for wildcard characters, it seems to be fine:


enter image description here

enter image description here

| improve this answer | |
  • 1
    Thats a great catch! Surprised to see the version without spaces show up when the query has spaces. – battery.cord Sep 5 '19 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.