Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Using the Schema Namespace

The Schema namespace provides classes and methods for working with schema metadata information. We implicitly import Schema.*, but you must fully qualify your uses of Schema namespace elements when they have naming conflicts with items in your unmanaged code. If your org contains an Apex class that has the same name as an sObject, add the Schema namespace prefix to the sObject name in your code.

You can omit the namespace when creating an instance of a schema class or when calling a schema method. For example, because the DescribeSObjectResult and FieldSet classes are in the Schema namespace, these code segments are equivalent.

1Schema.DescribeSObjectResult d = Account.sObjectType.getDescribe();
2Map<String, Schema.FieldSet> FSMap = d.fieldSets.getMap();

And:

1DescribeSObjectResult d = Account.sObjectType.getDescribe();
2Map<String, FieldSet> FSMap = d.fieldSets.getMap();

Using the Schema Namespace for Disambiguation

Use Schema.object_name to refer to an sObject that has the same name as a custom class. This disambiguation instructs the Apex runtime to use the sObject.

1public class Account {
2   public Integer myInteger;
3}
4
5// ...
6
7// Create a standard Account object myAccountSObject
8Schema.Account myAccountSObject = new Schema.Account();
9// Create accountClassInstance, a custom class in your org
10Account accountClassInstance = new Account();
11myAccountSObject.Name = 'Snazzy Account';
12accountClassInstance.myInteger = 1;