# fflib-apex-extensions ## Primitive Domain - SObject 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. ```apex public class Accounts extends fflib_SObjects2 implements IAccounts { ... } ``` ### Method reference Public methods - [getSObjectById](#getSObjectById) - [getRecords](#getRecords) Protected methods - [addError](#adderror) - [clearField / clearFields](#clearField) - [getDateFieldValues](#getDateFieldValues) - [getDateTimeFieldValues](#getDateTimeFieldValues) - [getDecimalFieldValues](#getDecimalFieldValues) - [getDoubleFieldValues](#getdoublefieldvalues) - [getFieldByField](#getfieldbyfield) - [getFieldsByField](#getfieldsbyfield) - [getIdFieldByStringField](#getidfieldbystringfield) - [getIdFieldByIdField](#getidfieldbyidfield) - [getIdFieldsByIdField](#getidfieldsbyidfield) - [getIdFieldValues](#getidfieldvalues) - [getIntegerFieldValues](#getintegerfieldvalues) - [getLongFieldValues](#getlongfieldvalues) - [getSObjectByIdField](#getsobjectbyidfield) - [getSObjectsByIdField](#getsobjectsbyidfield) - [getSObjectByStringField](#getsobjectbystringfield) - [getSObjectsByStringField](#getsobjectsbystringfield) - [getStringFieldByIdField](#getstringfieldbyidfield) - [getStringFieldByStringField](#getstringfieldbystringfield) - [getStringFieldValues](#getstringfieldvalues) - [setFieldValue](#setfieldvalue) _(Added method overload)_ #### getSObjectById Returns the contents of the Domain by their primary Key ('Id' field) `public Map getSObjectById()`


#### getRecords Returns only the SObjects from the domain matching the given Ids. `public List getRecords(Ids ids)`
`public List getRecords(Set ids)`

Return the SObject records contained in the domain matching the criteria - `public List getRecords(fflib_Criteria criteria)`



#### addError Adds an error message to the records in the domain `protected void addError(String message)`
`protected void addError(Schema.SObjectField sObjectField, String message)`


#### clearField Clear the field value on all the records of the domain `protected void clearField(Schema.SObjectField sObjectField)`
`protected void clearFields(Set sObjectFields)`


#### getDateFieldValues 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)`


#### getDateTimeFieldValues 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)`


#### getDecimalFieldValues 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)`


#### getDoubleFieldValues 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)`


#### getFieldByField Get a map with the values of two fields. Key fields containing null values are omitted `protected Map getFieldByField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Accounts accounts = Accounts.newInstance(records); Map accountNameById = accounts.getFieldByField(Account.Name, Account.Id); ```

#### getFieldsByField Get a map with the values of two fields. Key fields containing null values are omitted. `protected Map> getFieldsByField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Contacts contacts = Contacts.newInstance(records); Map> contactIdByAccountId = contacts.getFieldsByField(Contact.Id, Contact.AccountId); ```

#### getIdFieldByStringField Get a map with the string field as the key and the ID as values. Key fields containing null values are omitted. `protected Map getIdFieldByStringField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Contacts contacts = Contacts.newInstance(records); Map accountIdByContactId = contacts.getIdFieldByStringField(Contact.Id, Contact.Name); ```

#### getIdFieldByIdField Get a map with the values of two Id fields. Key fields containing null values are omitted. `protected Map getIdFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Contacts contacts = Contacts.newInstance(records); Map accountIdByContactId = contacts.getIdFieldByIdField(Contact.AccountId, Contact.Id); ```

#### getIdFieldsByIdField 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> getIdFieldsByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Contacts contacts = Contacts.newInstance(records); Map> contactIdByAccountId = contacts.getIdFieldsByIdField(Contact.Id, Contact.AccountId); ```

#### getIdFieldValues 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)`


#### getIntegerFieldValues 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)`


#### getLongFieldValues 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)`


#### getSObjectByIdField Get a map with the record mapped to the given Id field value. Key fields containing null values are omitted. `protected Map getSObjectByIdField(Schema.SObjectField sObjectField)` _Example_ ```apex Account account = Account.newInstance(records); Map accountById = account.getSObjectByIdField(Account.Id); ```

#### getSObjectsByIdField Get a map with the records mapped to the given Id field value. Key fields containing null values are omitted. `protected Map> getSObjectsByIdField(Schema.SObjectField sObjectField)` _Example_ ```apex Contacts contacts = Contacts.newInstance(records); Map> contactsByAccountId = contacts.getSObjectsByIdField(Contact.AccountId); ```

#### getSObjectByStringField Get a map with the record mapped to the given String field value. Key fields containing null values are omitted. `protected Map getSObjectByStringField(Schema.SObjectField sObjectField)` _Example_ ```apex Account account = Account.newInstance(records); Map accountByNumber = account.getSObjectByStringField(Account.AccountNumber); ```

#### getSObjectsByStringField Get a map with the records mapped to the given String field value. Key fields containing null values are omitted. `protected Map> getSObjectsByStringField(Schema.SObjectField sObjectField)` _Example_ ```apex Account account = Account.newInstance(records); Map accountByName = account.getSObjectsByStringField(Account.AccountName); ```

#### getStringFieldByIdField Get a map with the given String field value mapped to the given Id field. Key fields containing null values are omitted. `protected Map getStringFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Account account = Account.newInstance(records); Map accountNameById = account.getStringFieldByIdField(Account.AccountName, Account.Id); ```

#### getStringFieldByStringField Get a map with the records mapped to the given String field value. Key fields containing null values are omitted. `protected Map getStringFieldByStringField(Schema.SObjectField valueField, Schema.SObjectField keyField)` _Example_ ```apex Account account = Account.newInstance(records); Map accountNameById = account.getStringFieldByStringField(Account.AccountName, Account.Id); ```

#### getStringFieldValues 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)`


#### setFieldValue 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)`