function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swamy PRNswamy PRN 

Select object in dropdown list

Hi, This is swamy

 

   I want details regarding something related to objects.

 Iam creating  a dropdown list for objects,if i select a single object  thus related records should be displayed in a pageblock table .If i change the object name from list thus records only displayed in a table.

 

 If anyone know's intimate me....plz

Shebin-KVP Business SolnsShebin-KVP Business Solns

Hai Swamy,

 

   I have solution for your problem, which is  using salesforce schema and describe methods.

  See how nice salesforce is handling all these metadata information!!!.

 

  Below is the attched Visualforce Markup and Apex code.

 

 Please modify accordingly as per your requirement.

 

 

<apex:page controller="objectController">
    <apex:form>
         <apex:selectList  value="{!object_Name}" size="1">
          <apex:selectOptions  value="{!options_Objects}"/>
              <apex:actionSupport  action="{!childList}"  event="onchange"/>
         </apex:selectList>
         <apex:selectList   >
              <apex:selectOptions  value="{!options_Childs}"/>
         </apex:selectList>
    </apex:form> 
</apex:page>
public class objectController
{
 
  Public  List<SelectOption> options_Objects {get;set;}
  Public  List<SelectOption> options_Childs  {get;set;}
  Public  String object_Name{get;set;} 
  
  public  objectController()
  {
       options_Objects  =   new  List<SelectOption>();
       options_Childs   =   new  List<SelectOption>();
       List<Schema.SObjectType> GlobalDescribe     = Schema.getGlobalDescribe().Values();
       for( Schema.SObjectType ObjectType :GlobalDescribe)
       {
        options_Objects.add( new SelectOption( ObjectType.getDescribe().getLocalName() ,  ObjectType.getDescribe().getLabel() ) );  
       } 
   } 
   public void childList()
   { 
        options_Childs.clear();
        Schema.DescribeSObjectResult R =  Schema.getGlobalDescribe().get( object_Name).getDescribe();
        for( Schema.ChildRelationship  Child: R.getChildRelationships())
        {
         options_Childs.add( new SelectOption( Child.getChildSObject().getDescribe().getLocalName() ,  Child.getChildSObject().getDescribe().getLabel()  ) );  
        }
     
   }




}

 

 Please have a look and feel free for further clarifications..

 

Thanks.

Shebin,

KVP Business Solutions,

Bangalore.

pavan kumar 762pavan kumar 762
hi,
subin,
when we are selecting the object in drop down,display the records of that perticular object.