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
JosephJJosephJ 

Cannot search fields on Task object

I'm using SOSL to search Subject,Status and Activitydate on Task object . The search works for only Subject but when i enter status say 'In progress' it is not displaying.

How can i make search run on Subject,Status or by Activitydate as well ? Also,how do i make search work for enhance list created instead of rendering values down ? PLease help .


  <apex:page standardController="Task" extensions="TaskSearchController">
    <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>

      <apex:form id="searchForm">
      <apex:PageBlock mode="edit">       
      <apex:pageblockSection id="searchBlockSection">
       <apex:pageBlockSectionItem id="searchBlockSectionItem">
        <apex:outputLabel >Keyword</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">

                </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
    </apex:pageblockSection>
    <apex:actionStatus id="status" startText="Searching... please wait..."/>       
    <apex:pageBlocksection id="renderBlock" >
        <apex:pageblocktable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">
            <apex:outputLink value="/{!o.Id}">{!o.Subject}</apex:outputLink>
            <apex:column value="{!o.Subject}"/>

        </apex:pageblocktable>      
    </apex:pageBlocksection>
   </apex:pageblock>
  </apex:form>
   </apex:page>


    // Apex class


     public class TaskSearchController
    {
       public apexpages.standardController controller{get;set;}
       public Task l;
       public List<Task> searchResults {get; set; }

      public string searchText
      {
       get
       {
         if (searchText==null) searchText = '';
         return searchText;
       }
      set;
       }

     public TaskSearchController(ApexPages.StandardController controller)
     {
        this.controller = controller;
        this.l = (Task) controller.getRecord();
      }

    public PageReference search()
    {
      if(SearchResults == null)
      {
        SearchResults = new List<Task>();
      }
     else
     {
        SearchResults.Clear();
     }

     String qry = 'Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' Order By Subject,Status';
  // System.debug(qry);
    SearchResults = Database.query(qry);
   // System.debug(SearchResults);
   return null;
    }
   }
Best Answer chosen by JosephJ
Sonam_SFDCSonam_SFDC
I tried your code in my test ORG and following is the change required to get the search bar above the enhanced list
Bring the enhanced list tag below the line where you close the form tag:

</apex:pageblock>
  </apex:form>
   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
   </apex:page>

and remove it from top of the page.

Hit the best answer button if you think this helped you and can help others.

All Answers

Sonam_SFDCSonam_SFDC
The SOQL in the controller is only fltering the records that contain the searchstring in the subject:
String qry = 'Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' Order By Subject,Status';


update this to be:
String qry = 'Select Id, Subject,Status from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'  Order By Subject,Status';

such that it also gets records which have the search string in the Status
JosephJJosephJ
Sonam,

Its working. But how do i get the search textbox on top of the related list  ? Its displaying me down the related list.
Sonam_SFDCSonam_SFDC
get the search box  out of the pageblock tag and the search box should appear outside the related list

Following lines outside the <apex:pageblock>  

<apex:pageBlockSectionItem id="searchBlockSectionItem">
        <apex:outputLabel >Keyword</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">

                </apex:inputtext>
                <apex:commandButton Id="btnSearch" action="{!Search}" rerender="renderBlock" status="status" title="Search" value="Search">                    </apex:commandButton>
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
JosephJJosephJ
Thanks Sonam for the quick response . Putting above lines/search box ouside the <Apex:pageblock > gives me an error saying that pageblocksection component should be in <apex:pageblock> which is right according to doc.Please help me to achive this . You have increased my knowledge.
Sonam_SFDCSonam_SFDC
I tried your code in my test ORG and following is the change required to get the search bar above the enhanced list
Bring the enhanced list tag below the line where you close the form tag:

</apex:pageblock>
  </apex:form>
   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/>
   </apex:page>

and remove it from top of the page.

Hit the best answer button if you think this helped you and can help others.
This was selected as the best answer
JosephJJosephJ
Bingo ! This worked..Thank you .