We are trying to develop our code using fflib. Can we access relationship fields directly in the child domain class or do we need to use the parent object domain to access the field values and sent it over as a parameter to the child domain methods?
Approach 1:
main.cls:
List<Contact> contactResult = ContactsSelector.newInstance().selectByEmails(emails);
IContacts contacts = Contacts.newInstance(contactResult);
Map<String, Set<Id>> contactEmailAndAccountCountryToContactIds = contacts.getEmailAndAccountCountryToIds();
Contacts.cls
getEmailAndAccountCountryToIds() {
for (Contact contact : getRecords()) {
String key = contact.Email + '-'+ contact.Account.BillingCountry;
//...
}
}
Approach 2:
main.cls:
List<Contact> contactResult = ContactsSelector.newInstance().selectByEmails(emails);
IContacts contacts = Contacts.newInstance(contactResult);
IAccounts accounts = Accounts.newInstance(contacts.getAccounts());
Map<String, Set<Id>> contactEmailAndAccountCountryToContactIds = contacts.getEmailAndAccountCountryToIds(accounts.getCountryById());
Contacts.cls
getAccounts() {
List<Account> accounts = new List<Account>();
for (Contact contact : getRecords()) {
accounts.add(contact.Account)
}
return accounts;
}
getEmailAndAccountCountryToIds(Map<Id,String> countryByAccountId) {
for (Contact contact : getRecords()) {
String key = contact.Email + '-'+ countryByAccountId.get(contact.AccountId);
//...
}
}