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
force shahidforce shahid 

plz check dis code friends

 When I select accname and click the FIND button i need to display those name records . There is no error , but I didn't get the records. Plz check and suggest me where is the problem and also i nned to display these records in another VF page. How it is ? I think Using page reference  ri8 ?


VF code:

<apex:page controller="accountfiltercon">
    <apex:form >
        <apex:pageBlock>
          <apex:pageBlockSection title="select picklist field value">
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
      </apex:pageBlockSection>  
         <apex:pageBlockSection title="List of Account Records">
             <apex:pageBlockTable value="{!arecs}" var="item">
                 <apex:column value="{!item.id}"/>
                 <apex:column value="{!item.name}"/>
                 <apex:column value="{!item.billingcity}"/>
                 <apex:column value="{!item.phone}"/>
             </apex:pageBlockTable>
             <!--apex:pageBlockButtons-->
                 <apex:commandButton value="FIND" action="{!pf}"/>
             <!--/apex:pageBlockButtons-->
         </apex:pageBlockSection>   
     </apex:pageBlock>       
    </apex:form>
</apex:page>

Apex Code:

public class accountfiltercon {
    Public string selectedname{get;set;}
    public list<account> arecs{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> pickname = new List<selectoption>();
            pickname.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry,billingcity FROM Account]){
            pickname.add(new selectoption(acc.id,acc.name));
            }
            return pickname; 
        }
    public void pf(){
        list<list<sobject>> lf=[find:selectedname in all fields returning account(id,name,billingcity,phone)];
    
    
    arecs=[select id,name,billingcity,phone from account where name=:selectedname];
    }
}

All Answers

Nagendra ChinchinadaNagendra Chinchinada
Hi Shahid,
Table must be rerender of Account Table after Account search is done, so it will display queried Accounts. See below code. code in Bold letters is added.

<apex:page controller="accountfiltercon">
    <apex:form >
        <apex:pageBlock>
          <apex:pageBlockSection title="select picklist field value">
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
      </apex:pageBlockSection>  
         <apex:pageBlockSection id="AccTable" title="List of Account Records">
             <apex:pageBlockTable value="{!arecs}" var="item">
                 <apex:column value="{!item.id}"/>
                 <apex:column value="{!item.name}"/>
                 <apex:column value="{!item.billingcity}"/>
                 <apex:column value="{!item.phone}"/>
             </apex:pageBlockTable>
             <!--apex:pageBlockButtons-->
                 <apex:commandButton value="FIND" action="{!pf}" rerender="AccTable" />
             <!--/apex:pageBlockButtons-->
         </apex:pageBlockSection>   
     </apex:pageBlock>       
    </apex:form>
</apex:page>
force shahidforce shahid
Hi Prasad,

It doesn't work

After i click FIND button , there is  no action 
 
Nagendra ChinchinadaNagendra Chinchinada
Here is the working code,

public class accountfiltercon {
    Public string selectedname{get;set;}
    public list<account> arecs{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> pickname = new List<selectoption>();
            pickname.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry,billingcity FROM Account limit 10]){
            pickname.add(new selectoption(acc.Name,acc.name));
            }
            return pickname; 
        }
    public void pf(){
        list<list<sobject>> lf=[find:selectedname in all fields returning account(id,name,billingcity,phone)];
    system.debug('selectedname '+selectedname);
    
        arecs = new list<account>();
    arecs=[select id,name,billingcity,phone from account where name=:selectedname];
    }
}




VF page,

<apex:page controller="accountfiltercon">
    <apex:form >
        <apex:pageMessages></apex:pageMessages>
        <apex:pageBlock>
          <apex:pageBlockSection title="select picklist field value">
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
      </apex:pageBlockSection>  
         <apex:pageBlockSection id="AccTable" title="List of Account Records">
             <apex:pageBlockTable value="{!arecs}" var="item">
                 <apex:column value="{!item.id}"/>
                 <apex:column value="{!item.name}"/>
                 <apex:column value="{!item.billingcity}"/>
                 <apex:column value="{!item.phone}"/>
             </apex:pageBlockTable>
             <!--apex:pageBlockButtons-->
                 <apex:commandButton value="FIND" action="{!pf}" rerender="AccTable" />
             <!--/apex:pageBlockButtons-->
         </apex:pageBlockSection>   
     </apex:pageBlock>       
    </apex:form>
</apex:page>
force shahidforce shahid
Thank you Prasad
Now its working. 

pickname.add(new selectoption(acc.Name,acc.name));

here why we use 2 time acc.name ? i didn't understand. Can u please explain me ?

Also how to display records in another VF page when i click FIND button
DixitSDixitS
please fallow the link to know about "why we use 2 time acc.name ? in -->  pickname.add(new selectoption(acc.Name,acc.name));"
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_selectoption.htm
force shahidforce shahid
Thanks Dixit.
Now I understnad.
DixitSDixitS
Your most Welcome Shahid