Domain SObjects - wimvelzeboer/fflib-apex-extensions GitHub Wiki
The primitive domain SObject adds a lot of additional getter methods to the domain. It also includes getting Maps directly from the domain. (see the get...By...
methods)
This class should be used to extend Domain classes.
public class Accounts extends SObjects implements IAccounts
{
...
}
Public methods
Protected methods
- addError
- clearField / clearFields
- getDateFieldValues
- getDateTimeFieldValues
- getDecimalFieldValues
- getDoubleFieldValues
- getFieldByField
- getFieldsByField
- getIdFieldByIdField
- getIdFieldsByIdField
- getIdFieldValues
- getIntegerFieldValues
- getLongFieldValues
- getSObjectByIdField
- getSObjectsByIdField
- getSObjectByStringField
- getSObjectsByStringField
- getStringFieldByIdField
- getStringFieldByStringField
- getStringFieldValues
- setFieldValue (Added method overload)
Returns the contents of the Domain by their primary Key ('Id' field)
public Map<Id, SObject> getSObjectById()
Returns only the SObjects from the domain matching the given Ids.
public List<SObject> getRecords(Ids ids)
public List<SObject> getRecords(Set<Id> ids)
Return the SObject records contained in the domain matching the criteria
-
public List<SObject> getRecords(fflib_Criteria criteria)
Adds an error message to the records in the domain
protected void addError(String message)
protected void addError(Schema.SObjectField sObjectField, String message)
Clear the field value on all the records of the domain
protected void clearField(Schema.SObjectField sObjectField)
protected void clearFields(Set<Schema.SObjectField> sObjectFields)
Get the Date values from the given SObjectField, null values will be omitted. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Dates getDateFieldValues(Schema.SObjectField sObjectField)
protected Dates getDateFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Get the Datetime values from the given SObjectField, null values will be omitted. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected DateTimes getDateTimeFieldValues(Schema.SObjectField sObjectField)
protected DateTimes getDateTimeFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Get the Decimal values from the given SObjectField, null values will be omitted. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Decimals getDecimalFieldValues(Schema.SObjectField sObjectField)
protected Decimals getDecimalFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Get the Double values from the given SObjectField, null values will be omitted. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Doubles getDoubleFieldValues(Schema.SObjectField sObjectField)
protected Doubles getDoubleFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Get a map with the values of two fields. Key fields containing null values are omitted
protected Map<Object, Object> getFieldByField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Accounts accounts = Accounts.newInstance(records);
Map<Object, Object> accountNameById = accounts.getFieldByField(Account.Name, Account.Id);
Get a map with the values of two fields. Key fields containing null values are omitted.
protected Map<Object, Set<Object>> getFieldsByField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Contacts contacts = Contacts.newInstance(records);
Map<Object, Set<Object>> contactIdByAccountId = contacts.getFieldsByField(Contact.Id, Contact.AccountId);
Get a map with the values of two Id fields. Key fields containing null values are omitted.
protected Map<Id, Id> getIdFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Contacts contacts = Contacts.newInstance(records);
Map<Id, Id> accountIdByContactId = contacts.getIdFieldByIdField(Contact.AccountId, Contact.Id);
Get a map with the values of two Id fields with a one to many relation. Key fields containing null values are omitted.
protected Map<Id, Set<Id>> getIdFieldsByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Contacts contacts = Contacts.newInstance(records);
Map<Id, Set<Id>> contactIdByAccountId = contacts.getIdFieldsByIdField(Contact.Id, Contact.AccountId);
Gets the values from the given Id field. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Ids getIdFieldValues(Schema.SObjectField sObjectField)
protected Ids getIdFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Gets the values from the given Integer field. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Integers getIntegerFieldValues(Schema.SObjectField sObjectField)
protected Integers getIntegerFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Gets the values from the given Long field. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Longs getLongFieldValues(Schema.SObjectField sObjectField)
protected Longs getLongFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
Get a map with the record mapped to the given Id field value. Key fields containing null values are omitted.
protected Map<Id, SObject> getSObjectByIdField(Schema.SObjectField sObjectField)
Example
Account account = Account.newInstance(records);
Map<Id, SObject> accountById = account.getSObjectByIdField(Account.Id);
Get a map with the records mapped to the given Id field value. Key fields containing null values are omitted.
protected Map<Id, List<SObject>> getSObjectsByIdField(Schema.SObjectField sObjectField)
Example
Contacts contacts = Contacts.newInstance(records);
Map<Id, List<SObject>> contactsByAccountId = contacts.getSObjectsByIdField(Contact.AccountId);
Get a map with the record mapped to the given String field value. Key fields containing null values are omitted.
protected Map<String, SObject> getSObjectByStringField(Schema.SObjectField sObjectField)
Example
Account account = Account.newInstance(records);
Map<String, SObject> accountByNumber = account.getSObjectByStringField(Account.AccountNumber);
Get a map with the records mapped to the given String field value. Key fields containing null values are omitted.
protected Map<String, List<SObject>> getSObjectsByStringField(Schema.SObjectField sObjectField)
Example
Account account = Account.newInstance(records);
Map<String, SObject> accountByName = account.getSObjectsByStringField(Account.AccountName);
Get a map with the given String field value mapped to the given Id field. Key fields containing null values are omitted.
protected Map<Id, String> getStringFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Account account = Account.newInstance(records);
Map<Id, String> accountNameById = account.getStringFieldByIdField(Account.AccountName, Account.Id);
Get a map with the records mapped to the given String field value. Key fields containing null values are omitted.
protected Map<String, String> getStringFieldByStringField(Schema.SObjectField valueField, Schema.SObjectField keyField)
Example
Account account = Account.newInstance(records);
Map<Id, String> accountNameById = account.getStringFieldByStringField(Account.AccountName, Account.Id);
Gets the values for the provided String field. If a criteria is provided, only the value of the records matches the criteria will be returned.
protected Strings getStringFieldValues(Schema.SObjectField sObjectField)
protected Strings getStringFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria)
This method overload is added to give the value to the given field only when the criteria are met for the record.
protected void setFieldValue(Schema.SObjectField sObjectField, Object value, fflib_Criteria criteria)