Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

SObjects

global virtual inherited sharing class SObjects extends TriggerHandler
DescriptionBase 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

  Properties

ns
global static String 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
global SObjectType sObjType
SObjectType associated with this object

Constructors

  SObjects

global SObjects(String objType)
DescriptionCreate an SObjects instance of type objType
ThrowsInvalidParameterValueException if objType is blank or invalid

  SObjects

global SObjects(SObjectType objType)
DescriptionCreate an SObjects instance of type objType
ThrowsInvalidParameterValueException if objType is null

  SObjects

global SObjects(SObject record)
DescriptionCreate an SObjects instance with a single record
ThrowsInvalidParameterValueException if record is null

  SObjects

global SObjects(SObject[] records)
DescriptionCreate an SObjects instance with records
ThrowsInvalidParameterValueException if records is null or invalid

Methods

  dmlDelete

global Database.DeleteResult[] dmlDelete()
DescriptionPerform a delete with allOrNone = true.
ThrowsSecurityException if records of this type are not deletable by the current user

  dmlDelete

global Database.DeleteResult[] dmlDelete(Boolean allOrNone)
DescriptionPerform a delete, specifying allOrNone.
ThrowsSecurityException if records of this type are not deletable by the current user

  dmlInsert

global Database.SaveResult[] dmlInsert()
DescriptionPerform an insert with allOrNone = true.
ThrowsSecurityException if records of this type are not createable by the current user

  dmlInsert

global Database.SaveResult[] dmlInsert(Boolean allOrNone)
DescriptionPerform an insert, specifying allOrNone.
ThrowsSecurityException if records of this type are not createable by the current user

  dmlInsert

global Database.SaveResult[] dmlInsert(Database.DMLOptions dmlOptions)
DescriptionPerform an insert, specifying dmlOptions.
ThrowsSecurityException if records of this type are not createable by the current user

  dmlUndelete

global Database.UndeleteResult[] dmlUndelete()
DescriptionPerform an undelete with allOrNone = true.
ThrowsSecurityException if records of this type are not undeletable by the current user

  dmlUndelete

global Database.UndeleteResult[] dmlUndelete(Boolean allOrNone)
DescriptionPerform an undelete, specifying allOrNone.
ThrowsSecurityException if records of this type are not undeletable by the current user

  dmlUpdate

global Database.SaveResult[] dmlUpdate()
DescriptionPerform an update with allOrNone = true.
ThrowsSecurityException if records of this type are not updateable by the current user

  dmlUpdate

global Database.SaveResult[] dmlUpdate(Boolean allOrNone)
DescriptionPerform an update, specifying allOrNone.
ThrowsSecurityException if records of this type are not updateable by the current user

  dmlUpsert

global Database.UpsertResult[] dmlUpsert()
DescriptionPerform an upsert with allOrNone = true.
ThrowsSecurityException if records of this type are not upsertable by the current user

  dmlUpsert

global Database.UpsertResult[] dmlUpsert(SObjectField field)
DescriptionPerform an upsert with allOrNone = true, specifying the key field.
ThrowsSecurityException if records of this type are not upsertable by the current user

  dmlUpsert

global Database.UpsertResult[] dmlUpsert(Boolean allOrNone)
DescriptionPerform an upsert, specifying allOrNone.
ThrowsSecurityException if records of this type are not upsertable by the current user

  dmlUpsert

global Database.UpsertResult[] dmlUpsert(SObjectField field, Boolean allOrNone)
DescriptionPerform an upsert, specifying the key field and allOrNone.
ThrowsSecurityException if records of this type are not upsertable by the current user

  getDescribe

global static DescribeSObjectResult getDescribe(SObjectType objType)
Returnsthe corresponding DescribeSObjectResult
ThrowsInvalidParameterValueException if objType is null

  getDescribe

global static DescribeSObjectResult getDescribe(String objType)
Returnsthe corresponding DescribeSObjectResult, or null if objType is invalid
ThrowsInvalidParameterValueException if objType is null or blank

  getField

global SObjectField getField(String fieldPath)
Returnsthe SObjectField for the specified fieldPath, or null if either is invalid

  getFields

global Map<String,SObjectField> getFields()
Returnsall fields for this SObject

  getFieldToRecord

global Map<Object, SObject> getFieldToRecord(SObjectField field)
Returnsa 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.
ThrowsInvalidParameterValueException if field is null

  getFieldToRecords

global Map<Object, SObject[]> getFieldToRecords(SObjectField field)
Returnsa map of all unique "field" values to their records. Note that uniqueness of the returned keys is case sensitive.
ThrowsInvalidParameterValueException if field is null

  getFieldValue

global static Object getFieldValue(SObject record, String field)
Returnsthe record's value for the specified field. This method supports "dot notation" (i.e. Grandparent__r.Parent__r.Field)
ThrowsInvalidParameterValueException if field is blank
ThrowsSObjectException if field is invalid

  getFieldValues

global Set<Object> getFieldValues(SObjectField field)
Returnsthe set of all unique values for the "field" of all records. Note that uniqueness of the returned values is case sensitive.
ThrowsInvalidParameterValueException if field is null

  getPickListValues

global static Set<String> getPickListValues(SObjectField field)
Returnsthe values for the specified picklist field
ThrowsInvalidParameterValueException if field is null

  isFieldAccessible

global Boolean isFieldAccessible(SObjectField field)

  isFieldAccessible

global Boolean isFieldAccessible(String field)

  isFieldUpdateable

global Boolean isFieldUpdateable(SObjectField field)

  isFieldUpdateable

global Boolean isFieldUpdateable(String field)

  isPicklistValue

global static Boolean isPicklistValue(String value, SObjectField field)
Returnstrue if the specified value is valid for the picklist field
ThrowsInvalidParameterValueException if field is null

  processSaveResults

global Integer processSaveResults(String logName, Database.SaveResult[] results)
Returnsnumber of successes; log errors

  processUpsertResults

global Integer processUpsertResults(String logName, Database.UpsertResult[] results)
Returnsnumber of successes; log errors

  setEnforceSecurity

global void setEnforceSecurity(Boolean enforceSecurity)
DescriptionCheck and enforce security in DML operations

  truncate

global static Object truncate(SObjectField field, Object value)
DescriptionTruncate 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);
Parameterfield: the field
Parametervalue: the value to be truncated
Returnsthe truncated value
ThrowsInvalidParameterValueException if field is null