Salesforce Asked by Robert Sösemann on October 4, 2021
In my app, I get passed in user-generated SOQL query strings and need to validate and modify them. For that, I would need a parser that can extract me chunks They contain many SOQL features like:
I tried to:
Now I need your help to eighter point me to an existing solution that I didn’t find yet or help me understand how to make 1) or 2) work.
Please also don’t close-vote this question as too broad. Nobody is harmed when we leave it to hang around. Eventually, someone will be motivated by it to write such a parser.
I would really advise you not to do this.
Apex in its current form is really not suited for parsing and - more importantly - user-generated SOQL strings is a big security red flag. I know it's probably not the answer you wanted, but my advice would be to have a user-generated object-representation of the query (for example, an object representation of the fields, the objects, the filters, etc) and generate the SOQL downstream. This would avoid the parsing problem entirely and let you handle security robustly.
Plus, it's a fun object-oriented design exercise.
Correct answer by Lorenzo Frattini on October 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP