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
Nitin SharmaNitin Sharma 

Create a VF Page to search all the contacts, accounts and opportunities at the same time with the name that we enter in the text box. The result should be displayed in 3 different tables in the same page.

I created vfpage and it saved but no result displayed.My code given below:
VFpage:
<apex:page standardController="Account"  extensions="Searchclass" tabStyle="User">  
  <apex:form > 
  <apex:sectionHeader title="User Global Search" subtitle="Result"/> 
  <apex:pageBlock >
      <apex:pageBlockSection columns="1">
          <apex:pageBlockSectionItem >
              <label>Quick Search</label>
              <apex:outputPanel >
                  <apex:inputText value="{!searchstring}" label="Input"/>
                  <apex:commandButton value="Search records" action="{!search}" reRender="pgId" status="ajaxId"/>
                  &nbsp;<apex:actionStatus startText="Searching..." id="ajaxId"></apex:actionStatus>
              </apex:outputPanel>
          </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
  </apex:pageBlock>
  
  
    
     
   <apex:pageBlock title="Search Account Result" >  
    <apex:pageblockTable value="{!acc}" var="a">  
      
     <apex:column headerValue="Name" >  
       <apex:outputlink >{!a.Name}</apex:outputlink>
     </apex:column> 
     <apex:column headerValue="Phone" >  
       <apex:outputlink >{!a.Phone}</apex:outputlink>
     </apex:column>
     
    </apex:pageBlockTable>     
   </apex:pageBlock>  

    <apex:pageBlock title="Search Contact Result" >  
    <apex:pageblockTable value="{!con}" var="c">  
     
     <apex:column headerValue="Name" >  
       <apex:outputlink >{!c.Name}</apex:outputlink>
     </apex:column> 
     <apex:column headerValue="Phone" >  
       <apex:outputlink >{!c.Phone}</apex:outputlink>
     </apex:column>
    
    </apex:pageBlockTable>     
   </apex:pageBlock>  
   
   
    <apex:pageBlock title="Search Opportunity Result" >  
    <apex:pageblockTable value="{!opty}" var="o">  
   
     <apex:column headerValue="Name" >  
       <apex:outputlink >{!o.Name}</apex:outputlink>
     </apex:column> 
     <apex:column headerValue="StageName" >  
       <apex:outputlink >{!o.StageName}</apex:outputlink>
     </apex:column>
     
    </apex:pageBlockTable>     
   </apex:pageBlock>  
  </apex:form>  
 </apex:page>

Extension class:
public with sharing class Searchclass {
  
   public list <Account> acc {get;set;}
   public list<Contact> con{get;set;}
   public list<Opportunity> opty{get;set;}
   public string searchstring {get;set;} 
   public string value1 {get;set;} 
   
   
    
   public Searchclass(ApexPages.StandardController controller) {
     
   }  
   public void search(){  
     if(searchstring != null && searchstring != '' ){  
     string searchquery='select Name, Phone from Account where Name like \'%'+searchstring+'%\'  Limit 10';  
     string searchquery1='select Name, Phone from Contact where Name like \'%'+searchstring+'%\'  Limit 10';
     string searchquery2='select Name, StageName from Opportunity where Name like \'%'+searchstring+'%\'  Limit 10';
     acc= Database.query(searchquery); 
     con= Database.query(searchquery1); 
     opty= Database.query(searchquery2); 
     }
     }
      }

Plz help
Best Answer chosen by Nitin Sharma
srlawr uksrlawr uk
the reRender id on your search button
 
rerender="pgid"


Doesn't rerender anything, because you haven't put that ID on your results areas...

Either wrap all your result tables in another element, like:
 
<apex:outputPanel id="pgid">

or give each block an ID and update your rerender:
 
<apex:pageBlock title="Search Opportunity Result" id="oppyPgId">

(etc) and
 
reRender"oppyPgIg, accPgId, conPgId"


 

All Answers

srlawr uksrlawr uk
the reRender id on your search button
 
rerender="pgid"


Doesn't rerender anything, because you haven't put that ID on your results areas...

Either wrap all your result tables in another element, like:
 
<apex:outputPanel id="pgid">

or give each block an ID and update your rerender:
 
<apex:pageBlock title="Search Opportunity Result" id="oppyPgId">

(etc) and
 
reRender"oppyPgIg, accPgId, conPgId"


 
This was selected as the best answer
Nitin SharmaNitin Sharma
Thanks srlawr.
Its working properly...
srlawr uksrlawr uk
No probs dude. Happy Christmas!
Nitin SharmaNitin Sharma
Happy Christmas..