1

What is the correct syntax for a query that retrieves all Accounts that have __Civil_ in the Name?

SELECT Id FROM Account WHERE (Name LIKE '%_Civil_%')

2 Answers 2

3

You should escape the _ because the _ is a wildcard that matches exactly one character.

The query would look like:

[SELECT Id, Name FROM Account WHERE Name LIKE '%\_Card\_%']

2

If you want to query the underscores, then you have to escape them using \. Like in:

...WHERE Name LIKE '\_\_Civil\_'

If you want to use them as wildcards for matching any character, then your query should work, although you don't need the ( and ) for it to work.

Please refer to the documentation of the WHERE condition, on the Comparison Operators section: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_where.htm

1
  • 1
    The irony of me not escaping my own escape slashes in the answer and they didn't show up hahahah Commented Mar 21, 2019 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .