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
lakshmi25lakshmi25 

please write the controller for this code

<apex:page controller="selectobject" >
<apex:form >
<apex:pageBlock id="pb">
<apex:outputLabel ><b>Objects :</b></apex:outputLabel>&nbsp;
<apex:SelectList value="{!selectedObject}" size="1" >
<apex:SelectOptions value="{!objectsList}"/>
<apex:actionSupport event="onchange" rerender="pb"/>
</apex:SelectList>
<apex:commandButton value="Get Fields" action="{!showFields}" reRender="pb1" status="fetchStatus" />&nbsp;
<apex:actionStatus id="fetchStatus" >
<apex:facet name="start">
<img src="/img/loading.gif" class="waitingImage" title="Please Wait..."/>
</apex:facet>
</apex:actionStatus> <br/><br/>
</apex:pageBlock>
<apex:pageBlock id="pb1">
<apex:SelectList value="{!selectedField}" size="1">
<apex:SelectOptions value="{!items}"/>
</apex:SelectList>
</apex:pageBlock>
</apex:form>
</apex:page>

neeedhelpneeedhelp

Here is the Controller Class

public class selectobject{
public string selectedObject{get;set;}
public list<selectoption> getobjectsList(){
    list<selectoption> option = new list<selectoption>();
    option.add(new selectoption('','--None--'));
    option.add(new selectoption('Test1','Test1'));
    option.add(new selectoption('Test2','Test2'));
    return option;
} 
public void showFields(){

}
public string selectedField{get;set;}
public list<selectoption> getitems(){
 list<selectoption> options = new list<selectoption>();
 if(selectedObject=='Test1'){   
    options.add(new selectoption('First','First'));
    options.add(new selectoption('Second','Second'));
  }  
 if(selectedObject=='Test2'){   
    options.add(new selectoption('Third','Third'));
    options.add(new selectoption('Fourth','Fourth'));
  }  
    return options;
    
} 
}

 I think this Solves your Issue

izayizay

APEX Controller:

 

public with sharing class selectobject {
    
    private Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();//Get all objects
    private List<Schema.SObjectField> fldObjMapValues = new List<Schema.SObjectField>();
        
    public String selectedObject { get; set; }//Hold selected object name
    public String selectedField { get; set; }//Hold selected field name
       
    public selectobject(){
        selectedObject = getObjectsList()[0].getValue();
        Schema.SObjectType selection = Schema.getGlobalDescribe().get(selectedObject);
        Map<String, Schema.SObjectField> fldObjMap = selection.getDescribe().fields.getMap();
        fldObjMapValues = fldObjMap.values();
    }
    
    public PageReference showFields() { 
        Schema.SObjectType selection = Schema.getGlobalDescribe().get(selectedObject);
        Map<String, Schema.SObjectField> fldObjMap = selection.getDescribe().fields.getMap();
        fldObjMapValues = fldObjMap.values();       
        return null;
    }
        
    //Returns the list of objects for the user to pick from
    public List<SelectOption> getObjectsList (){
        //The list to return to the page
        List<SelectOption> options = new List<SelectOption>();
        //For each object in the in the org...
        for(Schema.SObjectType sot : gd.values()){
            //Create a new SelectOption...
            SelectOption option = new SelectOption(
                sot.getDescribe().getName(),
                sot.getDescribe().getLabel()
            );
            //Add it to the list of options
            options.add(option);
        }
        //Sort the list
        options.sort();
        //Return the list
        return options ;
    }
    
    //Returns the list of fields for the user to pick from
    public List<SelectOption> getItems(){
        //The list to return to the page
        List<SelectOption> options = new List<SelectOption>();
        //For each field in the lead object...
        for(Schema.SObjectField s : fldObjMapValues){
            //Create a new SelectOption...
            SelectOption option = new SelectOption(
                s.getDescribe().getName(),
                s.getDescribe().getLabel()
            );
            //Add it to the list of options
            options.add(option);
        }
        //Sort the list
        options.sort();
        //Return the list
        return options;
    }    
}

 

 

VF Page:

 

<apex:page controller="selectobject" >
<apex:form >
<apex:pageBlock id="pb">
<apex:outputLabel ><b>Objects : </b></apex:outputLabel>&nbsp;
<apex:SelectList value="{!selectedObject}" size="1" >
<apex:SelectOptions value="{!objectsList}"/>
<apex:actionSupport event="onchange" action="{!showFields}" rerender="pb1, pb" status="fetchStatus"/>
</apex:SelectList>
<apex:actionStatus id="fetchStatus" >
<apex:facet name="start">
<img src="/img/loading.gif" class="waitingImage" title="Please Wait..."/>
</apex:facet>
</apex:actionStatus> <br/><br/>
</apex:pageBlock>
<apex:pageBlock id="pb1">
<apex:outputLabel ><b>Fields : </b></apex:outputLabel>&nbsp;
<apex:SelectList value="{!selectedField}" size="1">
<apex:SelectOptions value="{!items}"/>
</apex:SelectList>
</apex:pageBlock>
</apex:form>
</apex:page>

 

lakshmi25lakshmi25
very very thanks