I'd like to get a deeper understanding into the SOQL use of wildcards and the term 'Like'. I have the following query:
SELECT name, city, state
FROM Account
WHERE name LIKE '%'+:searchVar+'%'
Let us say my target account is called 'Salesforce StackExchange LLC'. Inserting this full string as my search yields the one correct result, 'Salesforce StackExchange LLC'. Good.
Then let's cut off some of the string and search for 'Salesforce StackExchange'. Now we get multiple results, one of which is our target. So far, all good.
Finally, if I cut off even more, say "Salesforce", I get a bunch of results, but my target is NO LONGER in the results. No good.
I would expect the behavior of the query to keep increasing the amount of results, but still retain all query results from prior searches. If a result comes up for 'Salesforce StackExchange', shouldn't it also come up for 'Salesforce'?
Reading the SOQL guide seems to confirm my above expectation:
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 LIKE Like 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 _.
So what's going on?
Thanks!
EDIT: actual SOQL code is below (in JS):
var searchQuery = $j('#searchQuery').val() || ' ';
var queryOptions = {
where: {
name: {like: '%'+searchQuery+'%'}
}
};
globals.destObjModel.retrieve(queryOptions, function(err, records, event){...}
Salesforce
then it should returnSalesforce StackExchange LLC
value.. I have tested this in my org it is returning