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 

I want to create a picklist field in visual force page.and values are account object Name field values?

When i select the drop down the account object name filed values are display in this picklist field. will you Plz suggest how to write code & How to create VF Page ?
Best Answer chosen by force shahid
Ragava reddyRagava reddy
Hi Shahid,

Can you please go throuh the below code it will helps for you,

<apex:page controller="accountfiltercon ">
    <apex:form >
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
    </apex:form>
</apex:page>

public class accountfiltercon {
    Public string selectedname{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> lstnamesel = new List<selectoption>();
            lstnamesel.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry FROM Account]){
            lstnamesel.add(new selectoption(acc.id,acc.name));
            }
            return lstnamesel; 
        }
}

Thanks,
Raghavendra Reddy.D

 

All Answers

Ragava reddyRagava reddy
Hi Shahid,

Can you please go throuh the below code it will helps for you,

<apex:page controller="accountfiltercon ">
    <apex:form >
    <apex:selectList size="1" value="{!selectedname}"> 
        <apex:selectOptions value="{!selectedaccnamefields}"/>  
    </apex:selectList>
    </apex:form>
</apex:page>

public class accountfiltercon {
    Public string selectedname{get;set;}
        Public List<Selectoption> getselectedaccnamefields(){
            List<Selectoption> lstnamesel = new List<selectoption>();
            lstnamesel.add(new selectOption('', '- None -'));
            for(Account acc :[SELECT id,name,phone,type,industry FROM Account]){
            lstnamesel.add(new selectoption(acc.id,acc.name));
            }
            return lstnamesel; 
        }
}

Thanks,
Raghavendra Reddy.D

 
This was selected as the best answer
force shahidforce shahid
Thank You Raghav.
Thank you so much
Ragava reddyRagava reddy
Welcome Shahid,I think above solution is hepls for you, then please check the best answer.

Thanks,
Raghavendra reddy.D
force shahidforce shahid
Sorry ,

I forgot.

Thanks

 
force shahidforce shahid
HI Raghav, 

I do some changes in above code based on my requirement. 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];
    }
}
Ragava reddyRagava reddy
Hi Shahid,

Yup Right ,use pagereference :
PageReference pr = new PageReference('/apex/yourVFPageName');
pr.getParameters().put('key','value');
pr.setRedirect(true);

Use below code on your page:

 public List<Account> acclst{get; set;}
Public Dynamicfiltercon(){
        acclst=new List<Account>([SELECT id,name FROM Account]);
    }

public void ShowTable()  
    {  
        
       acclst=new List<Account>([SELECT id,name FROM Account WHERE id=:selectedname]);
       system.debug('@@@@acclstvalue:'+acclst);
    } 


<apex:commandButton value="Show Table" action="{!ShowTable}"/>  
    
    <apex:pageBlockTable value="{!acclst}" var="rec">  
        <apex:column value="{!rec.name}" />  
    </apex:pageBlockTable> 

Thanks,
Raghavendra Reddy.D

 
Ragava reddyRagava reddy
Public string selectedname{get;set;} 
 
Nishant Bodhtree 8Nishant Bodhtree 8

 
·         Create a Visual Force Page with below mentioned parameters:
1.       Drop Down option with ability to select an object to be searched. Objects are mentioned below:
§  Account,
§  Lead
2.       Drop down with filter values:
§  Custom – Upon selection user needs to enter Date range i.e. “From” & “To”
§  Monthly – Upon selection user needs to select a Month & Year
§  Yearly –  Upon selection user needs to select a Year
3.       Search Button – On click it should return results based on record created date that matches above mentioned drop down filters.