Sunday, May 24, 2015

Schema Programming in Apex and its usage in Visualforce Page.

Schema Programming in Apex and its usage in Visualforce Page.


Schema give the meta data information about the data (Object, Fields).

Schema Methods :

1). public static Map<String, Schema.SObjectType> getGlobalDescribe()
   
 This method returns a map of all the Sobject names as keys and Sobject val tokens as Values.


Ex:

Display all the list of objects available in the salesforce organization in the Visualfoce page.


Controller Class:

public class SchemaDescribeExample {
    public List<SelectOption> options;
    
    public list<SelectOption> getOptions(){
        return options;
    }
    
    public SchemaDescribeExample(){
        options = new List<SelectOption>();
        Map<String, Schema.SObjectType> schemaMap = schema.getGlobalDescribe();
        Set<String> objectSet = schemaMap.keySet();
        for(String str:objectSet){
            //praparing label and values in selection option.
            SelectOption op =new SelectOption(str,str);
            options.add(op);
        }
    }
    
    

}


VF Page:

<apex:page controller="SchemaDescribeExample">
 <apex:form >
  <Apex:selectList size="1">
    <apex:selectOptions value="{!options}"></apex:selectOptions>
   
  </Apex:selectList>
 </apex:form>
</apex:page>



That's it.. now it will display the list of all the objects in picklist.


More about Dynamic Apex:



Schema Programming in Apex and its usage in Visualforce Page.




2 comments:

Unknown said...

I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Salesforce, kindly contact us http://www.maxmunus.com/contact
MaxMunus Offer World Class Virtual Instructor led training on Salesforce. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us.
Nitesh Kumar
MaxMunus
E-mail: nitesh@maxmunus.com
Skype id: nitesh_maxmunus
Ph:(+91) 8553912023
http://www.maxmunus.com/


Anjali Siva said...

Thanks for this article, your post helps me to understand the future and career prospects. Keep updating your blog with the latest information.
Salesforce Training in Chennai
Salesforce Training
Salesforce course in Chennai
AngularJS Training in Chennai
ccna course in Chennai
PHP Training in Chennai
gst Training in Chennai
Tally course in Chennai
Salesforce Training in Anna Nagar
Salesforce course

Post a Comment

 
| ,