You need to sign in to do that
Don't have an account?
Vinay J
Breaking text string to smaller parts
I have a text field which saves query like:-
SELECT Id FROM Object WHERE fieldA = TRUE and fieldB = null
Now, based on some other fields on which user provides input, I need to parse the query, remove some of the fields from where clause and add some other.. Can someone please help me in breaking down the query saved in a text field to smaller parts. The keywords 'Where', 'and' and 'Limit' will always be there in the query.
SELECT Id FROM Object WHERE fieldA = TRUE and fieldB = null
Now, based on some other fields on which user provides input, I need to parse the query, remove some of the fields from where clause and add some other.. Can someone please help me in breaking down the query saved in a text field to smaller parts. The keywords 'Where', 'and' and 'Limit' will always be there in the query.
http://corycowgill.blogspot.sg/2011/01/building-dynamic-soql-select-all-query.html
Use dynamic query concept to from your SOQL query based on the conditions and data entered by the user:
Below is the sample :
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
if you let users store query strings in a textfield which are dynamically parsed you always run into the problem of possible SOQL-injections. It is the same with Balaji's solution.
Read more here: https://www.salesforce.com/us/developer/docs/pages/Content/pages_security_tips_soql_injection.htm
Best,
Andreas
Thanks for your reple. Looks like I couldn't explain what I want.
I know how to form a query dynamically and execute it. I need help with regular expressions. The query SELECT Id FROM Object WHERE fieldA = TRUE and fieldB = null is already saved in a text field. Now, for example, if user changes a picklist/lookup value, the query should be again modified based on the selection and should be updated. This all will happen in after trigger. Need help for how can I cut the existing query in to parts..