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

fetching salesforce account object record data into the select list .. is it possible ,,???

here i should get the account object record data in the from of the select list ??  is it possible ..
Scenario 2: i need to display the childrecords (say contact records)in the another selectlist , on selecting the parent record...
how is it possible in salesforce??
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vanisree,

Greetings to you!

Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

<apex:page controller="AccConPicklistC">
    <apex:pageMessages />
    <apex:form >
        <apex:pageBlock title="Account Name" id="op">
            Account Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <apex:selectList value="{!selectedAccId}" size="1" >                                 
                <apex:selectOptions value="{!AccountNames}"/>
                <apex:actionSupport event="onchange" action="{!cont}" />
            <apex:outputPanel rendered="{!isShow}" id="op2">
                Related Contact Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <apex:selectList value="{!selectedConId}" size="1"  id="a" >
                    <apex:selectOptions value="{!ContactNames}" />
                    <apex:actionSupport event="onchange" action="{!oppo}" />
            <apex:outputPanel rendered="{!isShow1}" id="op3">
                Related Opportunity Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <apex:selectList value="{!selectedOppId}" size="1" id="o">
                    <apex:selectOptions value="{!OpportunityNames}" />

public class AccConPicklistC {
    public List<SelectOption> ContactNames{set;get;}
    public List<SelectOption> OpportunityNames{set;get;}
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
    public String selectedOppId{get;set;}
    public Boolean isShow {get;set;}
    public Boolean isShow1 {get;set;}
    public AccConPicklistC(){
        ContactNames = new List<SelectOption>();
        OpportunityNames = new List<SelectOption>();
    public List<SelectOption> getAccountNames() {
        List<SelectOption> accOptions= new List<SelectOption>();
        accOptions.add( new SelectOption('','--Select--'));
        for( Account acc : [select Id,name from Account ] ) {
            accOptions.add( new SelectOption(acc.Id,;
        return accOptions;
    public void cont() {
		List<Contact> contact = new List<Contact>();
        if(selectedAccId != null) {     
            contact = [select Id,name,accountid from contact where accountid=:selectedAccId];
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No Related Contact Found'));
            for(Contact con : contact)
                ContactNames.add(new SelectOption(con.Id,;
    public void oppo() {
        List<Opportunity> opportunity = new List<Opportunity>();
        if(selectedConId != null){     
            opportunity = [select Id, Name, accountid from Opportunity 
                                    where accountid IN (SELECT AccountId from Contact WHERE Id =:selectedConId)];
            isShow1 = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No Related Opportunity Found'));
            isShow1 = true;
            for(Opportunity opp : opportunity)
                OpportunityNames.add(new SelectOption(opp.Id, opp.Name));

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 the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
hi khan anas, is it possible to add and delte the selected , on can add the new account record and new contact record, edit the record and save and delete the record.. can it is achived in the selectoption ...??

thanks and regards.
vanisree sfdc