You need to sign in to do that
Don't have an account?
RobJCowell
SOQLBuilder and pseudo-dynamic queries
So I'm using Richard Vanhook's SOQLBuilder from the apex-lang code library and I'm trying to migrate my string-concatenation SQL code to the new approach. The problem I'm hitting is when I need to add WHERE clauses dynamically depending on values set elsewhere.
Consider the following :-
companyquery = 'SELECT Event_to_Deal__r.Client_Company__r.ID FROM Event_Costs__c WHERE '; if (market != 'All') companyquery +='Event_to_Deal__r.LNOperation__c = \'' + market + '\''; if (industry != 'All') { if (companyquery.substring(companyquery.length()-6) != 'WHERE ') companyquery += ' AND '; companyquery += 'Event_to_Deal__r.Client_Company__r.Industry__c = \'' + industry + '\''; } if (sector != 'All') { if (companyquery.substring(companyquery.length()-6) != 'WHERE ') companyquery += ' AND '; companyquery += 'Event_to_Deal__r.Client_Company__r.Sectors__c = \'' + sector + '\''; } if (companyquery.substring(companyquery.length()-6) != 'WHERE ') companyquery += ' AND '; companyquery += 'Event_to_Deal__r.Status__c = \'Current\'';
Standard trickery for building these in strings, but how can you do the same kind of thing in SOQLBuilder? It doesn't seem to support being interrupted while you do an if statement, nor does it seem to be concatenatable.
Thanks
Rob
All Answers
Awesome, many thanks :manvery-happy: