Schema.DescribeFieldResult F = Account.Industry.getDescribe(); List<Schema.sObjectType> P = F.getReferenceTo();
The following are methods for SObjectType. All are instance methods.
public Schema.DescribeSObjectResult getDescribe()
public sObject newSObject()
Type: sObject
For an example, see Dynamic sObject Creation Example.
public sObject newSObject(ID id)
Type: sObject
For the argument, pass the ID of an existing record in the database.
After you create a new sObject, the sObject returned has all fields set to null. You can set any updateable field to desired values and then update the record in the database. Only the fields you set new values for are updated and all other fields which are not system fields are preserved.
public sObject newSObject(ID recordTypeId, Boolean loadDefaults)
Type: sObject
To learn more about default field values, see “Default Field Values” in the Salesforce online help.
This sample creates an account with any default values populated for its custom fields, if any, using the newSObject method. It also creates a second account for a specific record type. For both accounts, the sample sets the Name field, which is a required field that doesn’t have a default value, before inserting the new accounts.
// Create an account with predefined default values Account acct = (Account)Account.sObjectType.newSObject(null, true); // Provide a value for Name acct.Name = 'Acme'; // Insert new account insert acct; // This is for record type RT1 of Account ID rtId = [SELECT Id FROM RecordType WHERE sObjectType='Account' AND Name='RT1'].Id; Account acct2 = (Account)Account.sObjectType.newSObject(rtId, true); // Provide a value for Name acct2.Name = 'Acme2'; // Insert new account insert acct2;