+ Start a Discussion
Navneeth RajNavneeth Raj 

Invalid type: Schema.SObjectType ERROR2

public class SchemaExample1 {
    public Map<String,Schema.SObjectType> objMap {get;set;}
    public List<SelectOption> objs {set;get;}
    
    public SchemaExample1(){
        objMap=Schema.getGlobalDescribe();
        Set<String> key=objMap.keySet();
        
        objs=new List<SelectOption>();
        for(String s:keys){
            Schema.SObjectType sobj=oldMap.get(s);
            Schema.DescribeSObjectResult res=Sobj.getDescribe();
            SelectOption op=new selectOption(s,s);
            objs.add(op);
        }
    }
}User-added image
RatanRatan
I have used your code. Just modified few things and it is working in my developer console..
 
Map<String,Schema.SObjectType> objMap =Schema.getGlobalDescribe();
        Set<String> keys=objMap.keySet();
        
         List<SelectOption> objs =new List<SelectOption>();
        for(String s:keys){
            Schema.SObjectType sobj=objMap.get(s);
            Schema.DescribeSObjectResult res=Sobj.getDescribe();
            SelectOption op=new selectOption(s,s);
            objs.add(op);
        }

system.debug(objs);

Let me know if this is correct or not. 

If this solve you problem mark this as best answer to help others.
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that wil help u
public with sharing class ExtractSobject
{
    public String Sf{get;set;}
    public String Selectedobject { get; set; }    
  
        public List<SelectOption> getSelectedobjnames()
        {
            List<Schema.SObjectType> obj = Schema.getGlobalDescribe().Values();
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('--Select Object--','--Select Object--'));
            for(Schema.SObjectType st : obj)
            {
                if(Selectedobject == null || Selectedobject=='' )
                {       
                    Selectedobject = st.getDescribe().getName();
                }
                options.add(new SelectOption(st.getDescribe().getName(),st.getDescribe().getName()));
            }
            return options;
        }
       
        public List<SelectOption> getSelectedobjFields()
        {
            SObjectType objTyp = Schema.getGlobalDescribe().get(Selectedobject);
            DescribeSObjectResult objDef = objTyp.getDescribe();
            Map<String, SObjectField> fields = objDef.fields.getMap();

            Set<String> fieldSet = fields.keySet();
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('--Select Object--','--Select Object--'));
            for(String s:fieldSet)
            {  
                SObjectField Sobjfields = fields.get(s);
                DescribeFieldResult selectedField = Sobjfields.getDescribe();                 
                options.add(new SelectOption(selectedField.getName(),selectedField.getName()));
            }
            return options;
        }
}