SOQL Gotchas

There are a few things that trip me up when writing SOQL. I hope that sharing these gotchas will save you from making the same mistakes. Maybe writing this post will even help me remember this stuff too 🤔 Single Quotes NOT LIKE Filtering a DateTime with a Date Single Quotes It seems silly, but single quotes always trip me up. For example, I get an unexpected token error when querying for an Account named: Brett's Awesome Company This error happens because SOQL only sees: WHERE Name = 'Brett' . The s Awesome Company' part is hanging off the end, making it an unexpected token. We need to escape the single quote with a backslash (\) so SOQL can see WHERE Name = 'Brett\'s Awesome Company' . SOQL requires you to escape single quotes and a few other characters. A complete list with some examples can be found in the docs . NOT LIKE The LIKE comparison operator in SOQL will let you filter with a wildcard by using either the % or _