function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chikpeachikpea 

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:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<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}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

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

visualforce_devvisualforce_dev
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:
bob_buzzardbob_buzzard

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

chikpeachikpea

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 '*'.

 

Thanks

Bhaskar

VRayVRay

Chikpea, try something like this:

 

 public PageReference doSearch() {

try

    {
         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;

}