Apologies in advance if this question is too opinion based.
I am trying to lead us to a more defined separation of concerns in our Salesforce development. Currently, it is not much of a consideration in the development process.
I wanted to ask about how to keep the domain layer classes from getting bloated. In this case, I am talking about an FFLIB-style class that implements trigger handler logic. I understand and agree with the flow of dependencies Clients -> Service -> Domain.
This does seem to lead to all the business logic landing in a domain class at some point if our domains don't call services.
But if Domains contain object-specific behavior.. validations etc. And the service layer is core business logic it seems challenging never to have a Domain call a service.
If I have an AccountDomain and on-insert, if the account name contains "foo", I want notify our external Foo Account Partner. What is the best place for that logic to live?
I would normally think that onInsert calls FooVenderCalloutService()...
public override void onBeforeInsert() {
//if name.contains('foo){
//PartnerCallout callout = new PartnerCalloutService(foo);
}
}
after
context.