get all the fields of a object in apex

In order to get all the fields of a object in apex use getdescribe method on Schema.SObjectType as done in the example below. Select the object in the picklist, this would display all the fields for that object.

Visualforce Page
<apex:page controller="AllObjectsinOrg">
 <apex:form >
   <apex:pageBlock id="pgblck">
    <apex:outputlabel value="Object Name" for="ObjPickList"/>           <apex:selectList value="{!ObjectSelected}" multiselect="false" id="ObjPickList" size="1">
       <apex:selectOptions value="{!ObjList}"/>
       <apex:actionSupport event="onchange"  action="{!fieldsofObject}" rerender="pgblck" />  
     <apex:outputlabel value="Field Name" for="fldPickList" rendered="{!rendflag}"/>
        <apex:selectList value="{!fldselected}" multiselect="false" id="fldPickList" size="1" rendered="{!rendflag}">
            <apex:selectOptions value="{!FieldList}"/>                                 </apex:selectList>

public class AllObjectsinOrg {
 Public string ObjectSelected{get;set;}
 Public string fldselected{get;set;}
 Public Map<String, Schema.SObjectType> AllObjmap;
 Public Map <String, Schema.SObjectField> fieldMap;
 Public boolean rendflag{get;set;}
 Public AllObjectsinOrg(){
    AllObjmap = New Map<String, Schema.SObjectType>();
    AllObjmap = Schema.getGlobalDescribe();
    System.debug('******All object Names :'+ AllObjmap.keyset());
Public List<selectoption> getObjList(){
    List<selectoption> objList = new List<selectoption>();
    for(string s:AllObjmap.keyset()){
        objList.add(new selectoption(s,s));
  return objList;   
 Public List<selectoption> getFieldList(){
    List<selectoption> fldList = new List<selectoption>();
      for(string s:fieldMap.keyset()){
          fldList.add(new selectoption(s,s));
      if(fldList.size()== 0)
         fldList.add(new selectoption('--None--','--None--'));
  return fldList;   
  Public void fieldsofObject(){
    fieldMap = New Map <String, Schema.SObjectField>(); 
    fieldMap = AllObjmap.get(objectSelected).getDescribe().fields.getMap();
    System.debug('###### all fields of object## :' + fieldMap.keyset());
    rendflag = true;


  1. if i dont want all the objects but want only lead and campaign member then what should i do

    1. add if condition at

      for(string s:AllObjmap.keyset())
      if(s = 'lead ')
      objList.add(new selectoption(s,s));
      if(s = 'campaign member')
      objList.add(new selectoption(s,s));