You need to sign in to do that
Don't have an account?
balakrishna mandula 6
Dynamic apex
Hi,
I have a visulaforce page that is having picklist field which populates all the SObjects in my org.
My requirement is to populate all the fields of the particular SObject selected in piclist field.
e.g., If I select Account object in picklist field, then automatically all the fields to be displayed in the page.
Note: I used DescribeSobject ( Dynamic Apex) to display the objects.
VF:
<apex:page controller="CustomObjCon">
<script>
function showFieldsOfObject(){
showFields();
}
</script>
<apex:form >
CustomObjectNames:
<apex:selectList value="{!pickname}" multiselect="false" size="1" >
<apex:selectOptions value="{!names}"/>
</apex:selectList>
</apex:form>
</apex:page>
public class CustomObjCon
{
public String pickname { get; set; }
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
public List<SelectOption> getNames()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd)
{
// if(f.getDescribe().getName().contains('__c')) // for custom objects only
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
}
return options;
}
Thanks in Advance
Bala
I have a visulaforce page that is having picklist field which populates all the SObjects in my org.
My requirement is to populate all the fields of the particular SObject selected in piclist field.
e.g., If I select Account object in picklist field, then automatically all the fields to be displayed in the page.
Note: I used DescribeSobject ( Dynamic Apex) to display the objects.
VF:
<apex:page controller="CustomObjCon">
<script>
function showFieldsOfObject(){
showFields();
}
</script>
<apex:form >
CustomObjectNames:
<apex:selectList value="{!pickname}" multiselect="false" size="1" >
<apex:selectOptions value="{!names}"/>
</apex:selectList>
</apex:form>
</apex:page>
public class CustomObjCon
{
public String pickname { get; set; }
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
public List<SelectOption> getNames()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd)
{
// if(f.getDescribe().getName().contains('__c')) // for custom objects only
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
}
return options;
}
Thanks in Advance
Bala
<apex:page controller="vfcontrol" action="{!Objectnames}" showHeader="false" sidebar="false">
<apex:form >
<apex:selectList size="1">
<apex:selectOptions value="{!selectedObject}"/>
</apex:selectList><p/>
</apex:form>
</apex:page>
Conctroller:
Public Class vfcontrol{
public List<selectoption> selectedObject {get; set;}
public vfcontrol()
{
selectedObject = new List<selectoption>();
}
Public void Objectnames()
{
for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
selectedObject.add(new selectoption(objTyp.getDescribe().getLocalName().toLowerCase() ,objTyp.getDescribe().getLabel() ));
}
}
}
This will give you list of Sobjects in the org. with this use
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
get the fieldnme of the sobject. If your question is solved mark as answered
Thanks for ur reply.
I am getting all the objects in the , but I need to populate all the fields of the selected object.
e.g., If I select Opportunity object all the fields of the Opportunity should be populated automatically by changing picklist value.
Thanks,
Bala
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
get the fieldname of the sobject.
with this you wil get fieldnames