You need to sign in to do that
Don't have an account?
Hi All, I want pageblock to be refreshed if after one search I leave my input fields as blank then only error message must be shown but currently my page is showing error along with old matched result.
<apex:page standardController="Account" extensions="AccountSearchController">
<apex:form Id="FRM">
<apex:pagemessages />
<apex:pageblock title="Account Search" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!searchaccount}" reRender="op"/>
</apex:pageBlockButtons>
<apex:pageblocksection columns="2">
<apex:inputText label="Enter Account Name" value="{!acctname}"/><br/>
<apex:inputText label="Enter Account Phone" value="{!accntphone}"/><br/>
</apex:pageblocksection>
</apex:pageblock>
<apex:outputPanel id="op">
<apex:pageblock title="Account Search Results" rendered="{!showSearchResults}" id="pb">
<apex:pageBlockTable value="{!acntList}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageblock>
</apex:outputPanel>
</apex:form>
</apex:page>
public class AccountSearchController{
public String acctname{get;set;}
public String accntphone{get;set;}
public list<account> acntList{get;set;}
public boolean showSearchResults{get;set;}
//String myMsg{get;set;}
public AccountSearchController(){
system.debug('====== constr ');
}
public AccountSearchController(ApexPages.StandardController controller){
showSearchResults=false;
acntList= new list<account>();
system.debug('====== constr with param ');
}
public pagereference searchaccount(){
system.debug('=== acctname '+acctname );
system.debug('=== accntphone'+accntphone);
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
return null;
}
else if((acctname != null && acctname != '') || (accntphone != null && accntphone != '')){
acntList=[Select name,id,phone from account where (name=:acctname or phone=:accntphone) and (phone != null and name != null)];
System.debug('List of account values'+acntList);
System.debug('Size of account list'+acntList.size());
if(acntList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching account record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}else if(acntList.size() > 0){
showSearchResults=true;
}
}
return null;
}
}
Tried rerendering with ID of form as well, but no search results are getting displayed.
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
showsearchresults= false; //This is a solution
return null;
}
Well Thanks guys for your help.
All Answers
Hi
Hope below code helps you.
IF it helps you than please mark it as a solution and like it ENJOY APEX
Still same problem exists.
I tried searching a record using phone number and I got a search result now which is displayed in second pageblock. Now I have removed that phone number from input field and hit search button then error message displayed but old result still exits. I want to hide that pageblock section.
Hi Ashlekh,
Thanks for your quick reply but this way it is hiding result but page block is still on the page. I want to hide both result along with that pageblock.
Thanks
Jayati
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
showsearchresults= false; //This is a solution
return null;
}
Well Thanks guys for your help.