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
Anil Kumar DevarapuAnil Kumar Devarapu 

Page message text not visible

My intension is to display accounts and contacts in page block table which matches to my search keyword on VF page and This has been working, but When i hit search button without any keyword a custom page message should be displayed, any one please help me i did everything,
//VF Page
<apex:page controller="SearchAllCntrlr" >

<apex:form >
<apex:pageMessage summary=" <b>{!qc}</b> " severity="Confirm" strength="3" rendered="{!IF((acl.size>0)||(acu.size>0),true,false)}"  escape="false"/>
<apex:pageBlock title="Search Keyword">
 <apex:inputText value="{!Qstring}" label="Input" />   
  <apex:commandButton value="Search records" action="{!search}" /><br></br><br></br>
  Eg: Anil 
   </apex:pageBlock>
   <apex:pageBlock title="Account Result" rendered="{!acl.size!=0}">  
    <apex:pageblockTable value="{!acl}" var="a"  >  
     <apex:column HeaderValue="Accounts">  
      <!--<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>-->
      
      <apex:commandLink action="{!openAc}">
      <apex:param name="SelectedId" assignTo="{!selectedId}" value="{!a.id}"/>{!a.name}</apex:commandlink>
      </apex:column>
      
      
     <apex:column value="{!a.id}"/>  
    </apex:pageBlockTable>     
   </apex:pageBlock>
   
   <apex:pageBlock title="Contact Result" rendered="{!acu.size!=0}">
   <apex:pageblockTable value="{!acu}" var="b">
   <apex:column headerValue="Contacts">
   <apex:commandLink action="{!Openco}">
   <apex:param name="SelectedC" value="{!b.id}" assignTo="{!SelectedCC}"/>{!b.name}</apex:commandlink>
   </apex:column>
   </apex:pageblockTable>
   </apex:pageblock>
   
  
<apex:pageMessages escape="false"/>
  </apex:form> 

</apex:page>



________________

//CONTROLLER

public class SearchAllCntrlr 
{
public string SelectedId{get;set;}
public string selectedcc{get;set;}
public list<account> acl{get;set;}
public list<contact> acu{get;set;}
public string queri,queriC;
public string qc{get;set;}
public string Qstring{get;set;}

public string getqcp()
{
if(Qstring=='')
{
qc = 'You are viewing all Contacts and Accounts';
}
else { qc='Search Results for <b>"'+qstring+' "</b>';}
return qc;
}


public void search()
{
ASearch();
CSearch();

if(Qstring=='')
{
apexpages.Message msa = new Apexpages.Message(ApexPages.Severity.Confirm,'<b>You are Viewing All Accounts and Contacts</b> ');
        apexpages.addmessage(msa);  
}

if(acu.size()==0&&acl.size()==0)
{
apexpages.Message msa = new Apexpages.Message(ApexPages.Severity.FATAL,'There were no Results found  for <b> "'+qstring+' " </b> ');
        apexpages.addmessage(msa);  
}
else if(acl.size()==0)
{
 apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'There were no Results found on Accounts for <b>"'+qstring+' "</b>  ');
        apexpages.addmessage(msg);  

}
else if(acu.size()==0)
{
 apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'There were no Results found on Contacts for <b> "'+qstring+' " </b> ');
        apexpages.addmessage(msg);  

}

}
public SearchAllCntrlr()
{
//displ=true;
acl = new list<account>();
acu = new list<contact>();

}



public void ASearch()
{
queri = 'Select name from account where name like \'%'+Qstring+'%\' limit 50';
acl = database.query(queri );


}

public void CSearch()
{
queriC = 'Select name from Contact where name like \'%'+Qstring+'%\' limit 50';
acu = database.query(queriC);


}

public pagereference OpenAc()
{

pagereference pgs = new pagereference('/' +SelectedId);
pgs.setRedirect(true);
return pgs;

}

public pagereference OpenCo()
{
return new pagereference('/'+Selectedcc);
}


}
Best Answer chosen by Anil Kumar Devarapu
David ZhuDavid Zhu
replace line 53: public string qc{get;set;}
 by 

public string qc{get
{
     if(Qstring=='')
     {
         qc = 'You are viewing all Contacts and Accounts';
     }
    else { qc='Search Results for <b>"'+qstring+' "</b>';}
    return qc;
}
set;}


remove getqcp   // you might get confused wit qcp and qc

All Answers

David ZhuDavid Zhu
replace line 53: public string qc{get;set;}
 by 

public string qc{get
{
     if(Qstring=='')
     {
         qc = 'You are viewing all Contacts and Accounts';
     }
    else { qc='Search Results for <b>"'+qstring+' "</b>';}
    return qc;
}
set;}


remove getqcp   // you might get confused wit qcp and qc
This was selected as the best answer
Anil Kumar DevarapuAnil Kumar Devarapu
Hi David,
i didnt see that  'qcp' till now and really and i taught that it will never be displayed when multple page messages are there, i am new to salesforce, thanks Bro.  

Thank you so much!