Search code examples
salesforcevisualforceapex

I want to show the all the available custom object, Standard object based on custom selection


I have some requirement to list out all the custom objects and standard object detail with label name and api name using VF page. If I choose "Custom Object", Then page should list out all the custom object with the column of label name and api name. Thanks in advance.


Solution

  • I believe that your use case would be best suited to using the Schema.getGlobalDescribe method. With this method you can get a list of all the fields for a given object.

    Schema.getGlobalDescribe.get('Contact') returns a Schema.describeObjectResult object that can be further probed to get the field names and labels. To get a Map of all the fields on the Contact object you could call:

    Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap() 
    

    From that result you could iterate over the map to display all of the results. You would want to use an outputPanel with a nested repeat to produce the results.