You need to sign in to do that
Don't have an account?
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"/>
<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
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"/>
<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
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:
or give each block an ID and update your rerender:
(etc) and
All Answers
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:
or give each block an ID and update your rerender:
(etc) and
Its working properly...