一.SalesForce中Schema類的簡單介紹

一.Schema以及Schema NameSpace是什麼

在SalesForce中Schema指的是應用程序中對象(Object)以及對象之間的各類關係。
Schema NameSpace中包含了好多的類和方法,經過這些類和方法,能夠訪問Schema的一些基本信息。ide

二.Schema經常使用的類和方法

在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

相關文章
相關標籤/搜索