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_%')

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\_%']


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
    The irony of me not escaping my own escape slashes in the answer and they didn't show up hahahah – Stas Christiansen Mar 21 at 22:05

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.