Search code examples
automated-testssalesforcesoql

Is there a way to validate the syntax of a Salesforce.com's SOQL query without executing it?


I'm writing an API that converts actions performed by a non-technical user into Salesforce.com SOQL 'SELECT', 'UPSERT', and 'DELETE' statements. Is there any resource, library, etc. out there that could validate the syntax of the generated SOQL? I'm the only one at my company with any experience with SOQL, so I'd love to place it into a set of automated tests so that other developers enhancing (or fixing) the SOQL generation algorithm know if it's still functioning properly.

I know one solution here is to just make these integration tests. However, I'd rather avoid that for three reasons:

  1. I'd need to maintain another Salesforce.com account just for tests so we don't go over our API request cap.
  2. We'll end up chasing false positives whenever there are connectivity issues with Salesforce.com.
  3. Those other developers without experience will potentially need to figure out how to clean up the test Salesforce.com instance after DML operation test failures (which really means I'll need to clean up the instance whenever this occurs).

Solution

  • You might solve your problem by using the SoqlBuilder library. It generates SOQL for you and is capable of producing SOQL statements that would be quite error prone to create manually. The syntax is straight forward and I've used it extensively with very few issues.