When I was first introduced to Salesforce our company was medium size, with many straightforward Trigger based business processes. Since then we have merged into a large company with many strategic business units (SBUs) which our current org was not intended for.

With that said, we are currently refactoring our Transaction Script-like processes that manage the trigger-centric business logic, and we are looking to build a full-scale Domain Model. As I get started I was curious if there are any resources in the community that intentionally implement Martin Fowler's Patterns of Enterprise Application Architecture (PEAA) within the context of APEX?

At the moment Andrew Fawcett's, "FinancialForce Apex Common" which has been very helpful but also very deep to dive into, hoping to find some boilerplate examples with some simpler implementations to get things started so that I can implement a refactoring process and not a complete overwrite (he's Domain Model includes trigger handling, mock data, and structure that we are not ready for).

For example what classes (or groups of classes) would make up the following layers:

  • Service Layer
  • Domain Model
  • Unit of Work
  • and Data Mapper

2 Answers 2


Apex Common isn't that complex if you'll read through Andrew's introductory blog posts, especially Tips for Migrating to Apex Enterprise Patterns, and also samples code on Github.

I'm not aware of any other Apex implementations based on Martin Fowler's patterns. I was able to rewrite one of our app's code during migration from CRM objects to Custom objects model about a year ago by using Apex Common library, and this helped to reduce the following code enhancements efforts a LOT!

  • As I attempt this I again find it a very deep starting point. Just attempting to implement an example service requires SObjectUnitOfWork which implements ISObjectUnitOfWork and the service layer has a service() method that uses Application class which depends then depends on the interface class (IOpportunitiesService). I suppose I can cut back some of it but again looking for something that boils it down to the brass tax and outlines when each layer is implemented. Jan 19, 2017 at 20:17
  • I know, a lot of classes. But it all make sense and most of them are interfaces that help to cement all these classes into an enterprise grade app. Besides IOpportunitiesService service interface class, you would also need OpportunitiesService service class itself, and its implementation class OpportunitiesServiceImpl that holds all the logic ;)
    – o-lexi
    Jan 19, 2017 at 23:26
  • Do you know if his DataMapper layer is the SObjectSelector? Or what the differences are cause I don't see that transition very clearly Jan 20, 2017 at 0:27
  • feel free to join chat room where we can discuss this topic. P.S. I never used SE chat rooms before
    – o-lexi
    Jan 20, 2017 at 0:59

Found this while reading for the SF IAD exam: https://martinfowler.com/eaaCatalog/

  • I don't think that this provides an answer to the question. The purpose of the question, as I'm reading it, is to try to find other examples of a few specific patterns rather than asking the more basic question of "what are these different patterns?". Your link would help introduce someone to the patterns, but the question is more along the lines of "how do I apply this to Apex?".
    – Derek F
    Nov 15, 2018 at 19:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .