You need to sign in to do that
Don't have an account?
Clearing Search Results
Hi,
I am new to apex and visual force, but have picked up somethings from helpful posters online. I am needing some help in clearing search results. I have written the Visual Force Page code and the Apex Class controller code to contain a "Clear" button, but when clicked the clear button only clears the text input field on the search and not the search results grid. Any thoughts on how to expand the Apex Class to also clear the search results?
Visualforce Markup:
<apex:page controller="search" >
<apex:form >
<apex:outputLabel style="font-weight:bold;" value="Search By Client (Full Name or Email):" >
</apex:outputLabel>
<apex:inputText value="{!textData}"/>
<apex:commandButton value="Search" action="{!result}"/>
<apex:commandButton value="Clear" action="{!clear}"/>
<br>
</br>
<apex:pageBlock >
<apex:pageBlockTable value="{!opportunity}" var="opp">
<apex:column >
<apex:facet name="header">Full Name</apex:facet>
{!opp.Full_Name__c}
</apex:column>
<apex:column >
<apex:facet name="header">Technician</apex:facet>
{!opp.Technician__c}
</apex:column>
<apex:column >
<apex:facet name="header">Opportunity Year</apex:facet>
{!opp.Opportunity_Year__c}
</apex:column>
<apex:column >
<apex:facet name="header">Stage</apex:facet>
{!opp.StageName}
</apex:column>
<apex:column >
<apex:facet name="header">Status</apex:facet>
{!opp.Status__c}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public class search
{
public PageReference clear() {
textData = '';
return null;
}
public string textData{get;set;}
public List<Opportunity>Opportunity{get;set;}
public PageReference result()
{
Opportunity= [Select Full_Name__c, Technician__c, Opportunity_Year__c, StageName, Status__c from Opportunity where Full_Name__c Like :'%'+textData+'%' OR Client_Email__c Like :'%'+textData+'%'];
return null;
}
}
Thanks for your consideration!
Hi Mitchell,
Below is the Code for your requirement. Its working fine in my Org. Hopes it helps you.
Just add one more line to your clear Method :
Opportunity.clear();
so your Apex Class will be
public class search
{
public PageReference clear() {
textData = '';
Opportunity.clear();
}
public string textData{get;set;}
public List<Opportunity>Opportunity{get;set;}
public PageReference result()
{
Opportunity= [Select Full_Name__c, Technician__c, Opportunity_Year__c, StageName, Status__c from Opportunity where Full_Name__c Like :'%'+textData+'%' OR Client_Email__c Like :'%'+textData+'%'];
return null;
}
}
Please mark this answer best if it resolves your query.
Regard,
Suraj
All Answers
Hi Mitchell,
Below is the Code for your requirement. Its working fine in my Org. Hopes it helps you.
Just add one more line to your clear Method :
Opportunity.clear();
so your Apex Class will be
public class search
{
public PageReference clear() {
textData = '';
Opportunity.clear();
}
public string textData{get;set;}
public List<Opportunity>Opportunity{get;set;}
public PageReference result()
{
Opportunity= [Select Full_Name__c, Technician__c, Opportunity_Year__c, StageName, Status__c from Opportunity where Full_Name__c Like :'%'+textData+'%' OR Client_Email__c Like :'%'+textData+'%'];
return null;
}
}
Please mark this answer best if it resolves your query.
Regard,
Suraj
Thank you very much. You were extremely helpful. I think you overwrote "return null;" with the "Opportunity.clear();" line. The following is the apex class I used and it is working as the requirements dictate:
public class search
{
public PageReference clear() {
textData = '';
Opportunity.clear();
return null;
}
public string textData{get;set;}
public List<Opportunity>Opportunity{get;set;}
public PageReference result()
{
Opportunity= [Select Full_Name__c, Technician__c, Opportunity_Year__c, StageName, Status__c from Opportunity where Full_Name__c Like :'%'+textData+'%' OR Client_Email__c Like :'%'+textData+'%'];
return null;
}
}