Domain SObjects - wimvelzeboer/fflib-apex-extensions GitHub Wiki

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.

public class Accounts extends SObjects implements IAccounts
{
    ...
}

Method reference

Public methods

Protected methods

getSObjectById

Returns the contents of the Domain by their primary Key ('Id' field)

public Map<Id, SObject> getSObjectById()


getRecords

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)



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<Schema.SObjectField> 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<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);



getFieldsByField

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);



getIdFieldByIdField

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);



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<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);



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<Id, SObject> getSObjectByIdField(Schema.SObjectField sObjectField)

Example

Account account = Account.newInstance(records);
Map<Id, SObject> 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<Id, List<SObject>> getSObjectsByIdField(Schema.SObjectField sObjectField)

Example

Contacts contacts = Contacts.newInstance(records);
Map<Id, List<SObject>> 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<String, SObject> getSObjectByStringField(Schema.SObjectField sObjectField)

Example

Account account = Account.newInstance(records);
Map<String, SObject> 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<String, List<SObject>> getSObjectsByStringField(Schema.SObjectField sObjectField)

Example

Account account = Account.newInstance(records);
Map<String, SObject> 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<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);



getStringFieldByStringField

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);



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)






















⚠️ **GitHub.com Fallback** ⚠️