I am trying to get sObject fields name in 2nd pick list on the basis of selected object name in 1st pick list.
Here is my class..
public with sharing class ExtractSobject{
public list<SelectOption> fields { get; set; }
public String objectName { 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)
{
options.add(new SelectOption(st.getDescribe().getName(),st.getDescribe().getName()));
}
return options;
}
public String Sf{get;set;}
public List<SelectOption> objFields{get; set;}
public List<SelectOption> getSelectedobjFields()
{
SObjectType objTyp = Schema.getGlobalDescribe().get('Selectedobjnames');
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;
}
}
Page...
<apex:page controller="ExtractSobject">
<apex:form >
<apex:pageblock >
<apex:pageblocksection >
<apex:pageBlockSectionItem >
<apex:outputlabel value="Select Object"/>
<apex:selectList value="{!fields}" size="1">
<apex:selectoptions value="{!Selectedobjnames}"></apex:selectoptions>
<apex:actionSupport event="onchange" rerender="a"/>
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputPanel id="a">
<apex:outputLabel value="Object Fields" ></apex:outputLabel>
<apex:selectList value="{!Sf}" size="1">
<apex:selectOptions value="{!SelectedobjFields}" />
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
I am getting an exception
Attempt to de-reference a null object