SObjects Description Base class for object-specific domain classes. An instance of the class can represent a list of records and provide DML methods with automatic security checking and logging. This class also provides many static SObject and SObjectField -related utilities. Based loosely on Andrew Fawcett's Apex Enterprise Patterns
ns The SObject and field namespace prefix - if this class is in a managed package
records global SObject[] records
records that were passed into the constructor
sObjType
Constructors Description Create an SObjects instance of type objType Throws InvalidParameterValueException if objType is blank or invalid
Description Create an SObjects instance of type objType Throws InvalidParameterValueException if objType is null
Description Create an SObjects instance with a single record Throws InvalidParameterValueException if record is null
Description Create an SObjects instance with records Throws InvalidParameterValueException if records is null or invalid
Methods global Database.DeleteResult[] dmlDelete()
Description Perform a delete with allOrNone = true. Throws SecurityException if records of this type are not deletable by the current user
global Database.DeleteResult[] dmlDelete(
Boolean allOrNone)
Description Perform a delete, specifying allOrNone. Throws SecurityException if records of this type are not deletable by the current user
global Database.SaveResult[] dmlInsert()
Description Perform an insert with allOrNone = true. Throws SecurityException if records of this type are not createable by the current user
global Database.SaveResult[] dmlInsert(
Boolean allOrNone)
Description Perform an insert, specifying allOrNone. Throws SecurityException if records of this type are not createable by the current user
global Database.SaveResult[] dmlInsert(Database.DMLOptions dmlOptions)
Description Perform an insert, specifying dmlOptions. Throws SecurityException if records of this type are not createable by the current user
global Database.UndeleteResult[] dmlUndelete()
Description Perform an undelete with allOrNone = true. Throws SecurityException if records of this type are not undeletable by the current user
global Database.UndeleteResult[] dmlUndelete(
Boolean allOrNone)
Description Perform an undelete, specifying allOrNone. Throws SecurityException if records of this type are not undeletable by the current user
global Database.SaveResult[] dmlUpdate()
Description Perform an update with allOrNone = true. Throws SecurityException if records of this type are not updateable by the current user
global Database.SaveResult[] dmlUpdate(
Boolean allOrNone)
Description Perform an update, specifying allOrNone. Throws SecurityException if records of this type are not updateable by the current user
global Database.UpsertResult[] dmlUpsert()
Description Perform an upsert with allOrNone = true. Throws SecurityException if records of this type are not upsertable by the current user
global Database.UpsertResult[] dmlUpsert(
SObjectField field)
Description Perform an upsert with allOrNone = true, specifying the key field. Throws SecurityException if records of this type are not upsertable by the current user
global Database.UpsertResult[] dmlUpsert(
Boolean allOrNone)
Description Perform an upsert, specifying allOrNone. Throws SecurityException if records of this type are not upsertable by the current user
Description Perform an upsert, specifying the key field and allOrNone. Throws SecurityException if records of this type are not upsertable by the current user
global static DescribeSObjectResult getDescribe(
SObjectType objType)
Returns the corresponding DescribeSObjectResult Throws InvalidParameterValueException if objType is null
global static DescribeSObjectResult getDescribe(
String objType)
Returns the corresponding DescribeSObjectResult, or null if objType is invalid Throws InvalidParameterValueException if objType is null or blank
Returns the SObjectField for the specified fieldPath, or null if either is invalid
Returns all fields for this SObject
global Map<Object, SObject> getFieldToRecord(
SObjectField field)
Returns a map of each unique "field" values to its record. Note that uniqueness of the returned keys is case sensitive. If more than one record may have the same value, use getFieldToRecords instead. Throws InvalidParameterValueException if field is null
global Map<Object, SObject[]> getFieldToRecords(
SObjectField field)
Returns a map of all unique "field" values to their records. Note that uniqueness of the returned keys is case sensitive. Throws InvalidParameterValueException if field is null
global static Object getFieldValue(SObject record,
String field)
Returns the record's value for the specified field. This method supports "dot notation" (i.e. Grandparent__r.Parent__r.Field) Throws InvalidParameterValueException if field is blank Throws SObjectException if field is invalid
Returns the set of all unique values for the "field" of all records. Note that uniqueness of the returned values is case sensitive. Throws InvalidParameterValueException if field is null
Returns the values for the specified picklist field Throws InvalidParameterValueException if field is null
Returns true if the specified value is valid for the picklist field Throws InvalidParameterValueException if field is null
global
Integer processSaveResults(
String logName, Database.SaveResult[] results)
Returns number of successes; log errors
global
Integer processUpsertResults(
String logName, Database.UpsertResult[] results)
Returns number of successes; log errors
global void setEnforceSecurity(
Boolean enforceSecurity)
Description Check and enforce security in DML operations
global static Object truncate(
SObjectField field, Object value)
Description Truncate a field on an object to the max length of the field. Non-text fields are not affected. Example: // assuming Foo__c max length is 10 String newFoo = truncate(MyObj__c.Foo__c, '1234567890abc'); System.assertEquals('1234567890', newFoo); Parameter field: the field Parameter value: the value to be truncated Returns the truncated value Throws InvalidParameterValueException if field is null