在SalesForce中Schema指的是应用程序中对象(Object)以及对象之间的各类关系。
Schema NameSpace中包含了好多的类和方法,经过这些类和方法,能够访问Schema的一些基本信息。ide
在Schema NameSpace中包含了不少的类以及方法,在此并不会对全部的类和方法作介绍,只会对其中几个类的几个方法作简单介绍。this
1.Schema.getGlobalDescribe方法``
这个方法返回系统中全部sObject的一个Map,其中key是sObject Name,value是sObject token。
在此须要介绍一下的是什么是token,token的中文意思有象征性的,做为标志的意思。
在这里的token指的是sObject或者是Field,token中并不包含具体的信息,可是经过token能够获取到sObject或者Field的一些信息。
Schema.SObjectType是sObject token的类型。
Schema.SObjectField是Field token的类型。
Schema.DescribeSObjectResult是sObject describe的类型。
Schema.DescribeFieldResult是Field describe的类型。
代码示例:debug
Map<String, Schema.SObjectType> map = Schema.getGlobalDescribe(); system.debug(map);
上面代码运行输出的log是code
{acceptedeventrelation=AcceptedEventRelation, account=Account, accountchangeevent=AccountChangeEvent, accountcleaninfo=AccountCleanInfo, accountcontactrole=AccountContactRole, accountcontactrolechangeevent=AccountContactRoleChangeEvent, accountfeed=AccountFeed, accounthistory=AccountHistory, accountpartner=AccountPartner, accountshare=AccountShare, ...}
得到某一个sObject的token能够统统过一下两种方式:
例如要得到Account的token
⑴.对象
Schema.SObjectType type = account.sobjectType; system.debug(type);
上面代码的输出结果是:Account
(2).token
Account account = new Account(); system.debug(account.getsObjectType());
上面代码的输出结果一样是Accountget