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
vamshi Capvamshi Cap 

How to use values query once and use multiple times.

Hi Folks,

Here is small requirement, I have a picklist fields with different status in visualforce.. every time we change the status, acccording to status we are querying for the values and displaying in table but it is decreasing the perfomance. but instead of querying multiple times I want query once and use muliple time for each change?


for opportunites we have multiple stages ( open, pending, closed), if I want to display open oppys I am using <apex:actionSupport>  on change event I am querying for 'Open records and displaying same for remaining following same, if this is doing 1000 times we are quering 1000 times..but  I want query once but display values again and agian.

please help me it is urgesnt.



Hi Vamshi,

 try this Example:

visualforce page:
<apex:page controller="opportunityStageChange">
 function updateopportunitylist(){
 <apex:form id="theform">
  <h1>All Opportunity</h1>
   <apex:actionFunction name="refreshopportunitylist" action="{!fetchOpportunity}" reRender="theform" />
   <apex:selectList size="1" styleClass="form-control input-sm " value="{!selectedViewFilter}" onchange="updateopportunitylist()">
    <apex:selectOptions value="{!Opportunitystatus}"></apex:selectOptions>
   <apex:repeat value="{!lstopportunity}" var="opp">


Apex classes:
public class opportunityStageChange{
    public string selectedViewFilter{get;set;}
    public list<Opportunity> lstopportunity{get;set;}

public opportunityStageChange(){


    public void fetchOpportunity(){
    String searchCaseQuery = 'Select id,name,StageName From Opportunity ';
     String filterQuery = '';
         filterQuery += ' where StageName = \''+selectedViewFilter+'\''; 
        system.debug('check query ....'+filterQuery );                                    
    lstopportunity =  Database.query(searchCaseQuery+filterQuery);

public list<selectOption> getOpportunitystatus() {
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('None','-None-'));
        Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry p : ple)
        options.add(new SelectOption(p.getValue(), p.getValue()));        
        return options;


if your problem solve,mark as best answer.