Osama's Weblog

The place where you get updated!
  • rss
  • Home
  • Who am I?
  • RSS Feeds

How to: Retrieve a list of sObjects in Apex

Osama | May 11, 2010

Some one asked me how to retrieve a list of sObjects in an SF organization using Apex and bind it to a picklist in a VisualForce page.

List of sObjects is returned when you hit the schema of your SF organization. You can get the Label of sObjects as well as API names.

The following code snippet shows how to do the above mentioned task

VisualForce page:

<apex:page controller="Schema2" >
<apex:form >
<apex:SelectList value="{!val}" size="1">
<apex:selectOptions value="{!Name}"></apex:selectOptions>
</apex:SelectList>
</apex:form>
</apex:page>

Apex Controller Code:

public class Schema2 {
public String val {get;set;}
public List<SelectOption> getName()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values(); //extracts the List of sObjects in an organization
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd)
{
options.add(new SelectOption(f.getDescribe().getLabel(), f.getDescribe().getLabel()));
}
return options;
}
}

Feel free to ask any questions

  • Share/Bookmark
Categories
APEX, General, salesforce
Tags
APEX, salesforce, sObjects
Comments rss
Comments rss
Trackback
Trackback

« What is VMforce? Enforcing 1:1 relationship in Salesforce.com »

Leave a Reply

Click here to cancel reply.

My status

Categories

  • .NET
  • APEX
  • consulting
  • General
  • Oracle CRM on Demand
  • salesforce
  • Uncategorized
  • VisualForce

MM Did You Know?

The number of possible ways of playing the first four moves per side in a game of chess is 318,979,564,000.
Plugin by mmilan

Its all about cloud

Salesforce

.NET .NET 4.0 beta actionFunction actionSupport administrator android APEX Apex variable API button certification cloud computing consulting controller custom DoDirectPayment force.com GET goggles google html images input inputField JavaScript jquery master-detail matcher Parallel Programming parameters pattern paypal query string REGEX regular expression salesforce search url variable Visual Force VisualForce Visual Studio vmware web service XML PARSING DOM SAX STAX

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

My Tweets

Error: Please make sure the Twitter account is public.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox