+ Start a Discussion

Custom Object Search Page

I am trying to build a Search Page using SOSL query (just followed the example in VF guide book).


But the query doesn't reurn any row. Here is the Controller Code



public class woController {
String searchText;
List<Work_Order__c> workOrders = new List<Work_Order__c>();
public String getSearchText() {
return searchText;
public void setSearchText(String s) {
searchText = s;
public List<Work_Order__c> getWorkOrders() {
return workOrders;
public PageReference doSearch() {
workOrders = (List<Work_Order__c>)[FIND :searchText IN ALL FIELDS RETURNING
    Work_Order__c(Id, Name, Account__c, Service_Order__c, CreatedById, Work_Order_Status__c, CreatedDate)][0];
return null;



Here is the VF page code -


<apex:page controller="woController" tabStyle="Work_Order__c">
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Search Text</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Go!" action="{!doSearch}" rerender="block" status="status"/>
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable value="{!workOrders}" var="wo" rendered="true">
<apex:column value="{!wo.Name}"/>



If I use SOQL query for any particular field search, then it works. Any help would be appreciated.

For me it s returning search string matchs any 'text' fields value try search some text type fld value with and without '*' symbol. also next time paste code in 'insert code' option :smileytongue:

If you give us an example search string that you think should work, we might be able to help more.


We have work order statuses Unassigned, Assigned, Closed. I tried to search using string 'Closed', didn't get any result. I also tried with wildchar '*'.





Chikpea, try something like this:


 public PageReference doSearch() {


         workOrders = Database.query('SELECT Id, Name, Account__c, Service_Order__c, CreatedById, Work_Order_Status__c, CreatedDate FROM Work_Order__c WHERE Work_Order_Status__c = Closed LIMIT 100');

    catch (Exception e)
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));

return null;