--

Schema Programming in Apex / Dynamic Apex

Using Schema Programming in apex we can get metadata information about an sObject, tab, fieldname,custom or std object, application list etc.

Some major classes to know are below:

  1. Schema Class: Contains methods for obtaining schema describe information.
  2. SObjectType/SObjectField Class: Schema.sObjectType object is returned from the field describe result or sObject describe result using the getSObjectType method.

To Describe an sObject there are 2 simple steps:

Step 1: Create a token for object.

Step2: Describe the token.

Example: How to describe an sObject? eg: Account

Step1: Schema.sObjectType objToken = Account.sObjectType

Step2: Describe the object

Schema.DescribeSobjectResult dsr =objToken.getDescribe();

Describe SObject Example to get Object metadata
DescribeFieldResult Example to get Field Values

getGlobalDescribe: Returns a map of all sObject names (keys) to sObject tokens (values) for the standard and custom objects defined in your organization.

Map<sObjectNames-keys,sObjectTokens -values>

getGlobalDescribe to find Object Names in Org

--

--