Search code examples
sqlsalesforcesoql

Can you add an "AND field = value" to any SOQL query?


Assuming the query looks like this:

SELECT Id FROM Contact WHERE <some filter here>

and I want to add this:

AND field = value

In other words: if a query ends with the WHERE (doesn't have other sections/statements like "LIMIT" etc.), can you ALWAYS add an AND and have it not break?


Solution

  • Not sure I understood the question and I think that's not the best way to proceed. Anyway, I think it's always possibile. Pay attention to have a "some filter here" which does not end with a ";" and leave a blank space before the content you would like to add. Make sure the attributes you use are compatible with the selected table.