+ Start a Discussion
Padmanabhan KamuniPadmanabhan Kamuni 

I'm not able to see the picklist by using schema?? Kindly help

Hello,

Please find the code below and guide me.
public class Task17 {
    public Map<String, schema.SObjectType> allObjects {get;set;}
    public List<SelectOption>	objNames	{get; set;}
    public String objName {get; set;}
    public String selectedName	{get; set;}
	
    public Task17(){
        list<selectoption> objNames = new List<selectoption>();
        allObjects = schema.getGlobalDescribe();
        list<string> allNames = new list<string>(allObjects.keySet());
        //allNames.sort();
        system.debug('line 19'+allNames);
            for( String key1 : allNames){
                objNames.add(new SelectOption(key1,key1));
            }
        system.debug('Line22'+objNames);
        
    }    
}

VF page is below.
<apex:page controller="Task17" >
    <apex:form>
    	<apex:pageBlock>            
        	Please Select the obj
            <apex:selectList value="{!selectedName}">
            	<apex:selectOptions value="{!objNames}"/>
            </apex:selectList>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Pick list is not displaying.  Help..
 
Best Answer chosen by Padmanabhan Kamuni
Shalini RShalini R
Hi  Padmanabhan Kamuni,

I have changed some code from you written above. Please use this it is working fine.

public class ObjectNamesController{
    public Map<String, schema.SObjectType> allObjects {get;set;}
    public List<SelectOption> objNames {set;}
    public String selectedName  {get; set;}
     
    public ObjectNamesController(){

    }

    public List<SelectOption> getobjNames(){
        list<selectoption> objNames = new List<selectoption>();
        allObjects = schema.getGlobalDescribe();
        system.debug('allObjects'+allObjects );
        list<string> allNames = new list<string>(allObjects.keySet());
        system.debug('allNames'+allNames);
            for( String key1 : allNames){
                objNames.add(new SelectOption(key1,key1));
                system.debug('key1 '+key1 );
            }
        system.debug('Line22'+objNames); 
       return objNames;    
    }   
}

All Answers

Padmanabhan KamuniPadmanabhan Kamuni
The outputs is as blow. (picklist is showing no values in it)

User-added image
Shalini RShalini R
Hi  Padmanabhan Kamuni,

I have changed some code from you written above. Please use this it is working fine.

public class ObjectNamesController{
    public Map<String, schema.SObjectType> allObjects {get;set;}
    public List<SelectOption> objNames {set;}
    public String selectedName  {get; set;}
     
    public ObjectNamesController(){

    }

    public List<SelectOption> getobjNames(){
        list<selectoption> objNames = new List<selectoption>();
        allObjects = schema.getGlobalDescribe();
        system.debug('allObjects'+allObjects );
        list<string> allNames = new list<string>(allObjects.keySet());
        system.debug('allNames'+allNames);
            for( String key1 : allNames){
                objNames.add(new SelectOption(key1,key1));
                system.debug('key1 '+key1 );
            }
        system.debug('Line22'+objNames); 
       return objNames;    
    }   
}
This was selected as the best answer
Padmanabhan KamuniPadmanabhan Kamuni
Thank you Shalini
shweta chadha 4shweta chadha 4
use  public List<SelectOption> objNames {set;} instead of  public List<SelectOption> objNames {get;set;}
Padmanabhan KamuniPadmanabhan Kamuni
Thank you Shweta chadha 4. It's working but why the constructor cannot be used here.