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:
- Schema Class: Contains methods for obtaining schema describe information.
- 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();
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>