Tuesday, March 12, 2013

Displaying the all fields of a Object using Dynamic Apex in VF Page


Visualforce Page:

<apex:page controller="dynamiccls2" >
 <apex:repeat value="{!lst}" var="l">
     {!l}<br/>
 </apex:repeat>
</apex:page>

Apex Class:

public with sharing class dynamiccls2 {

    public List<string> lst { get; set; }

    public dynamiccls2(){
        lst= new List<String>();
        
       // Inorder to get fields of particular object 
        Map<String, Schema.sobjectField> mp = Schema.sobjectTYpe.Test__C.fields.getmap();
        System.debug(mp.values());
        List<Schema.sobjectField> lstfields = mp.values();
        for(Schema.sobjectField s:lstfields){
            lst.add(string.valueOf(s));
                                                             }
            lst.sort();       
                                    }
                                                              }

No comments:

Post a Comment