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
srikanth cheera 13srikanth cheera 13 

if i selected picklist only that record should be open

I have one vf dropdown list in that i have contact records 
if i salected contact record only that record shoulb open?
Khan AnasKhan Anas (Salesforce Developers) 
Hi Srikanth,

I trust you are doing very well.

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page Controller="ContactPicklistSelectC" >
    <apex:form >
        <apex:pageBlock title="Display Contact Details: ">
            
            <apex:pageBlockSection >
                <apex:outputLabel value="Contact Name: " />
                
                <apex:selectlist value="{!accid}" size="1" >
                    <apex:selectOptions value="{!contactNames}" />
                    <apex:actionSupport action="{!getDetails}" event="onchange" rerender="display"/>
                </apex:selectlist>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="display" title="Contact Details">
                <apex:outputField value="{!SelectedAcc.Name}"/>
                <apex:outputField value="{!SelectedAcc.Phone}"/>              
            </apex:pageBlockSection>    
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class ContactPicklistSelectC {
    
    public string accid {get; set;}
    public Contact SelectedAcc{get;set;}
    
    public list<selectoption> getContactNames() {
        
        list<selectoption> accoptions = new list<selectoption>();
        for (Contact acc : [SELECT id, Name FROM Contact]){
            accoptions.add(new selectoption(acc.id, acc.name));
        }  
        return accoptions;
    } 
    
    public void  getDetails() {
        
        SelectedAcc = new Contact();
        SelectedAcc = [SELECT id, Name, Phone FROM Contact WHERE id=:accid ];
        
    }
}


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas​
Khan AnasKhan Anas (Salesforce Developers) 
Hi Srikanth,

Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue. *(After you choose the best answer the question is marked as “resolved”)*

May the (Sales)force be with you :)
Happy Learning!

Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi Srikanth, 

Below code can fullfill your requirements. Hope this will work for you.

VF page:

<apex:page controller="samplecontact" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
 <apex:selectList value="{!numberLimit}" size="1" >
  <apex:selectOptions value="{!records}" />
  <apex:actionSupport action="{!showRecords}" event="onchange" reRender="pbt"/>
 </apex:selectList>
 </apex:pageBlockSectionItem>
 </apex:pageBlockSection> 
 <apex:pageBlockTable value="{!acts}" var="a" id="pbt">
  <apex:column value="{!a.name}" />
  <apex:column value="{!a.id}"/>
 </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

controller:

public with sharing class samplecontact {

   public integer numberLimit{get;set;}
   public list<selectOption> records{get;set;}
   public list<Contact> actss{get;set;}
   
   public samplecontact(){
   
   actss=new List<Contact>();
   records=new List<selectOption>();
   records.add(new selectoption('10','10'));
   records.add(new selectoption('20','20'));
   numberLimit=10;

   }
    
   public List<Contact> getActs(){
   actss=[select name,id from Contact limit :numberLimit];
   return actss;
   }  
    
   public pageReference showRecords(){
   return null;
   }
    
}


Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi