Salesforce-Separation-Of-Concerns-And-The-Apex-Common-Library icon indicating copy to clipboard operation
Salesforce-Separation-Of-Concerns-And-The-Apex-Common-Library copied to clipboard

DML in Service/Domain Layer

Open reignman5 opened this issue 4 years ago • 3 comments
trafficstars

You said in one video that we should put dmls in the service layer. Does this mean, that if we have a trigger that executes on afterInsert and creates a new record (different object), this logic should go into a service layer?

reignman5 avatar May 12 '21 12:05 reignman5

Although it's been a bit since I shot that video I believe I state something like, "The majority of dml should take place in a service layer 85-90%". There aren't a ton of situations that warrant dml operations outside of the service layer but every once in a while the domain layer warrants its own dml operations. If it is necessary to commit in the domain layer then it's fine to do it, just make sure it's truly object specific behavior and it's warranted to place that logic there.

Coding-With-The-Force avatar May 12 '21 13:05 Coding-With-The-Force

Thanks for the quick answer. So it would not be an "anti-pattern" to call a service layer from the domain layer? Or would I call the domain class of the object I want to create?

reignman5 avatar May 12 '21 13:05 reignman5

Sorry, I must've missed this, no it is definitely not an anti-pattern to do that. You can certainly call a service layer from the domain if necessary.

Coding-With-The-Force avatar May 19 '21 20:05 Coding-With-The-Force