Create a apex class controller:
======================================================
public class Sche{
public list<selectoption> obj {set;get;}
public list<selectoption> objc{set;get;}
public list<selectOption> flist {set;get;}
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public string o1 {set; get;}
public String o2 {get; set;}
public integer count {set;get;}
public Sche(){
obj=new list<selectoption>();
objc=new list<selectoption>();
flist=new list<selectoption>();
objc.add(new selectoption('None','-None-'));
obj.add(new selectoption('None','-None-'));
for(string k:schemaMap.keyset())
{
schema.SObjectType o = schemaMap.get(k);
schema.DescribeSObjectResult r= o.getDescribe();
if(r.isCustom())
{
objc.add(new selectoption(k,k));
}
else
{
obj.add(new selectoption(k,k));
}
}
objc.sort();
obj.sort();
}
public void show(){
flist.clear();
count=0;
o2=null;
map<string,schema.SobjectField> fldmap = schemaMap.get(o1).getDescribe().fields.getmap();
for(string k:fldmap.keyset())
{
flist.add(new selectoption(k,k));
count++;
}
}
public void show2(){
flist.clear();
count=0;
o1=null;
map<string,schema.SobjectField> fldmap = schemaMap.get(o2).getDescribe().fields.getmap();
for(string k:fldmap.keyset())
{
flist.add(new selectoption(k,k));
count++;
}
}
}
==============================================================
Create VF page:
<apex:page controller="Sche" title="Schema" >
<apex:sectionHeader title="Schema" subtitle="New Schema"/>
<apex:form >
<apex:pageBlock id="one" >
<apex:pageBlockSection collapsible="true" title="Schema Programing" >
<apex:selectList label="STANDERD OBJECT" size="1" value="{!o1}" >
<apex:actionSupport action="{!show}" event="onchange" reRender="one" />
<apex:selectOptions value="{!obj}" ></apex:selectOptions>
</apex:selectList>
<apex:selectList label=" CUSTOM OBJECT" size="1" value="{!o2}">
<apex:actionSupport action="{!show2}" event="onchange" reRender="one" />
<apex:selectOptions value="{!objc}" ></apex:selectOptions>
</apex:selectList>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!count} Fields In {!o1} {!o2}" />
<apex:selectList label="FIELDS" size="1" >
<apex:selectOptions value="{!Flist}" ></apex:selectOptions>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
No comments:
Post a Comment