token and describe result   Leave a comment

token 可看作是一个SObject 或是 SObject field的digest,每次需要的信息的时候还要还原成describe result.

sObject s = new Account();
// Verify that the generic sObject is an Account sObject

//sobject(多态上行以后的sobject对象,比如account, contact)对象的 getSObjectType() == 相应的具体sobject类的静态变量sobjectType.

System.assert(s.getsObjectType() == Account.sObjectType);

// Get the sObject describe result for the Account object
// sobject的describe result的类型名为:Schema.DescribeSObjectResult,为相应的token.getDescribe().

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

// Get the field describe result for the Name field on the Account object

//sobject的field的describe result的类型为 Schema.DescribeFieldResult.

// 也可以用静态变量Schema.sObjectType.Account.fields.Name来表示。

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name;

// Verify that the field token is the token for the Name field on an Account object

// field token可以为 Field DescribeFieldresult 的.getSObjectField().

// field token 也可以为 相应的具体sobject的相应的field,例如:Account.Name.

System.assert(f.getSObjectField() == Account.Name);

// Get the field describe result from the token

// 从token到Describe result, token.getDescribe()

f = f.getSObjectField().getDescribe();

//sobject token 的类型: Schema.sObjectType,  也可以用相关具体类的相关静态方法。

Schema.sObjectType t = Account.sObjectType;
Account A = new Account();

// 从sobject的对象到token, 对象.getSObjectType()
Schema.sObjectType T = A.getSObjectType();

public class sObjectTest {
{
// Create a generic sObject variable s
SObject s = Database.query(‘select id from account limit 1’);
// Verify if that sObject variable is an Account token
System.assertEquals(s.getSObjectType(), Account.sObjectType);
// Create a list of generic sObjects
List l = new Account[]{};
// Verify if the list of sObjects contains Account tokens

// sobject具体类的list的token跟相关的具体类的token是相同的
System.assertEquals(l.getSObjectType(), Account.sObjectType);
}}

// sobject的token 的类型是 Schema.sObjectType.

Schema.sObjectType t = Account.sObjectType;
Account A = new Account();

//对象的getSObjectTyp,为token, 类型为Schema.sObjectTyp
Schema.sObjectType T = A.getSObjectType();

public class sObjectTest {
{
// Create a generic sObject variable s
SObject s = Database.query(‘select id from account limit 1’);
// Verify if that sObject variable is an Account token
System.assertEquals(s.getSObjectType(), Account.sObjectType);
// Create a list of generic sObjects
List l = new Account[]{};
// Verify if the list of sObjects contains Account tokens
System.assertEquals(l.getSObjectType(), Account.sObjectType);
}}

//sobject describe result的类型为: Schema.DescribeSObjectResult.

//也可以为schema.SObjectType.Account.(相关的具体类型)

Schema.DescribeSObjectResult D = Account.sObjectType.getDescribe();
Schema.DescribeSObjectResult D = Schema.SObjectType.Account;

//Field的token的类型为Schema.SObjectField.

//其token可以直接从相关的sobject具体类到field,比如Account.AccountNumber.

Schema.SObjectField F = Account.AccountNumber;

// Get the describe result for the Name field on the Account object

//field的describe result的类型为:Schema.DescribeFieldResult. 或Schema.sObjectType.Account.fields.Name
Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name;
// Verify that the field token is the token for the Name field on an Account object

field token: describe result的对象的getSObject  f.getSObjectField() == Account.Name

System.assert(f.getSObjectField() == Account.Name);
// Get the describe result from the token
f = f.getSObjectField().getDescribe();

//Schema.DescribeFieldResul ==  Account.AccountNumber.getDescribe()

//Schema.DescribeFieldResult == Schema.SObjectType.Account.fields.Name

Schema.DescribeFieldResult F = Account.AccountNumber.getDescribe();
Schema.DescribeFieldResult F = Schema.SObjectType.Account.fields.Name;

//Map gd = Schema.getGlobalDescribe();
//Map M = Schema.SObjectType.Account.fields.getMap();

Map gd = Schema.getGlobalDescribe();
Map M = Schema.SObjectType.Account.fields.getMap();

Posted 2011年08月28日 by gw8310 in salesforce

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: