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

I am writing an API that translates actions performed by a non-technical user into Salesforce.com SOQL 'SELECT' , 'UPSERT' and 'DELETE' . Is there any resource, library, etc. that could check the syntax of the generated SOQL? I am the only one in my company with any experience with SOQL, so I would like to put it in a set of automated tests so that other developers who improve the SOQL generation algorithm (or fix) know that it is still functioning properly.

I know that one solution is to simply perform these integration tests. However, I would prefer to avoid this for three reasons:

  • I will need to support a different Salesforce.com account for tests only so that we don’t go to our API request.
  • As a result, we will pursue false positives when there are problems with communication with Salesforce.com.
  • Those other developers who are not experienced will potentially have to figure out how to clean up an instance of Salesforce.com after failed DML checks (which really means that I will need to clean up the instance whenever this happens).
+4
source share
4 answers

You can solve your problem with the SoqlBuilder library . It generates SOQL for you and is capable of generating SOQL statements that could be manually created if errors occurred. The syntax is simple and I have used it extensively with very few problems.

+2
source

I found another way to do this.

Salesforce.com posted its SOQL notation in the Backus-Noir Form (BNF) here: http://www.salesforce.com/us/developer/docs/api90/Content/sforce_api_calls_soql_bnf_notation.htm

This means that you can use a language recognition tool that supports BNF to analyze SOQL. One of the most common tools, ANTLR , does this and is free. Following the ANTLR example, pass the SOQL grammar to your grammar compiler to get Lexer and Parser in the language you need (C #, Java, Python, etc.). You can then pass the actual SOQL instructions that you want to validate to Lexer, and then your Lexer tokens to your Parser to break up the SOQL statements. If your Lexer or Parser fails, you have an invalid SOQL.

+2
source

I can't think of a way to do this outside of Salesforce (and even in Apex I only got one idea that might not work), but I can think of two suggestions that might help

  • Check requests by running them, but make them in batches using a custom web service. that is, write a web service in Apex that can take up to 100 query lines at once, run them and return the results. This would drastically reduce the number of API calls, but of course it would not work if you were expecting a trial and error setting in the user interface.

  • Use the metadata API to display information about all objects and their fields and use them to verify that at least the fields in the query are correct. Checking the other query syntax should be relatively straightforward, although conventions can be a bit tricky.

+1
source

You can use salesforce to develop nuget packages that use the SOAP API

0
source

Source: https://habr.com/ru/post/1393654/


All Articles