Schema Scenario -1

Create a picklist field in the vf page with list of all the subjects in your org and  when you select the subject corresponding description of the object should be displayed 

Apex: 

public class VfExampleSchema {
    public Map<String, Schema.SObjectType> sobt{set;get;}
    public List<SelectOption> opts{set;get;}
    public String selected{set;get;}
    public String result{set;get;}
    public VfExampleSchema(){
        sobt=schema.getGlobalDescribe();
        opts=new List<SelectOption>();
        Set<String> keys=sobt.keySet();
        for(String s:keys){
            SelectOption sp=new SelectOption(s,s);
            opts.add(sp);
        }
    }
    public void data(){
        Schema.SobjectType sot=sobt.get(selected);
        schema.DescribeSObjectResult reslt=sot.getDescribe();
        result= '=====>>>'+reslt;
    }

}

Vf Page:

<apex:page controller="VfExampleSchema">
    <apex:form >
    <apex:pageBlock >
        <apex:selectList value="{!selected}" size="1">
            <apex:selectOptions value="{!opts}">
                </apex:selectOptions>
            </apex:selectList>
            <apex:commandButton value="reslut" action="{!data}" />
            {!result}
        </apex:pageBlock>
    </apex:form>
</apex:page>



 Select any one of from the picklist

Click on  Button  Result






Comments

Popular posts from this blog

Page Layouts

SOQL Scenario-1