You need to sign in to do that
Don't have an account?
Dynamic SOQL
Hi,
I wrote Dynamic soql for getting records,but am not able to get the solution..Could any one resolve it..........
Error is::
System.QueryException: line 1:59 no viable alternative at character '%'
public PageReference gettin_objs() {
string fword= '%'+searchword+'%';
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
for(Schema.SObjectType f : gd){
if(searchword!=null || searchword!=''){
list<sobject> ss=Database.query('Select id,Name from '+f+'where Name Like: '+fword);
//if(ss.NOT(isempty())){
finalobj.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getName()));
// }
}
}
return null;
}
}
-------
v.f:
<apex:page controller="recsearchcls">
<apex:form >
<apex:PageBlock >
<br/><h1><b>Search In Multiple Objects</b></h1><br/><br/><br/>
<b>Enter Here:</b> <apex:inputtext value="{!searchword}" onkeydown="sss()">
<apex:actionfunction action="{!gettin_objs}" name="sss"/>
</apex:inputtext>
<apex:commandButton action="{!search}" value="Search"/>
<apex:pageBlockSection >
<apex:selectCheckboxes value="{!check}" style="float:left" layout="pageDirection" >
<apex:selectOptions value="{!ren}"/>
</apex:selectCheckboxes>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:form>
</apex:page>
Hi,
Try this
list<sobject> ss=Database.query(
'Select id,Name from '+f+'where Name Like'+'\'%'+String.escapeSingleQuotes(searchWord)+'%\'');
If this post solves your problem, kindly mark it as solution.
Thanks
Thanks For your Reply But geting same Error i.e
System.QueryException: unexpected token: Like
try this
In your call to Database.query() you are using a bind variable where it isn't needed -- simply surround the search filter in single quotes. This worked just fine for me:
Bind variable syntax (i.e. :myVariable) should be used inside bracket notation.
Regards,
Jeremy