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
sreejasreeja 

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.

Visualforce:
<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:selectList>
            
            <br/><br/>
            
            <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:selectList>
            </apex:outputPanel>
            <br/><br/>
            
            <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}" />
                </apex:selectList>
            </apex:outputPanel>
        </apex:pageBlock>               
    </apex:form>
</apex:page>

Controller:
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>();
        isShow=false;
        isShow1=false;
    }
    
    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,acc.name));
        }
        return accOptions;
    }
    
    public void cont() {
        ContactNames.clear();
		List<Contact> contact = new List<Contact>();
        if(selectedAccId != null) {     
            contact = [select Id,name,accountid from contact where accountid=:selectedAccId];
        }
        if(contact.isEmpty())
        {
            isShow=false;
            OpportunityNames.clear();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No Related Contact Found'));
        }
        else{
            for(Contact con : contact)
            {
                isShow=true;
                ContactNames.add(new SelectOption(con.Id, con.name));
            }
        }                  
    }
    
    public void oppo() {
        OpportunityNames.clear();
        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)];
        }                  
        if(opportunity.isEmpty())
        {
            isShow1 = false;
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No Related Opportunity Found'));
        }
        else{
            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
sreejasreeja
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