You need to sign in to do that
Don't have an account?
JosephJ
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;
}
}
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;
}
}
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
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
Its working. But how do i get the search textbox on top of the related list ? Its displaying me down 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>
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.