You need to sign in to do that
Don't have an account?
huniverse
set query condition in loop
hi
currently i am displaying fields in data table through following. i need to implement search and display. So is there any way to use qrystring in for loop below so search work fine along with datatable. Kindly suggest any idea, code, link.
// search logic
String qryString = 'select Id, Name,custom1__c,custom2__c from Account ' + sCondition ;
for(account c : [select Id, Name, custom1__c,custom2__c from Account]){
accountList.add(new aAccount(c));
}
Thanks in advance
You don't need to assign it to a separate list when doing your query. Just do this:
But remember, you must guard against SOQL injection attacks; while they are not nearly as devastating as SQL counterparts (i.e. they can't do ';DROP DATABASE org'), they could still possibly access records outside their scope (you use be using with sharing, of course, but still...) I recommend that you use variable binding with your dynamic query for maximum safety. Variable binding is done by preceding the variable name with a colon. I'd recommend that you read the documentation on dynamic SOQL for a full example on how this all works.