Apex Execution and Separation of Concerns
When starting to write Apex, it is tempting to start with an Apex Trigger or Apex controller class and to start placing the required logic in those classes to implement the desired functionality. This chapter will explore a different starting point, one that allows you to focus on writing application business logic (the core logic of your application) in a way that is independent of the calling context. It will also explain the benefits of this approach in terms of reuse, code maintainability, and flexibility, especially when applying code to different areas of the platform.
We will explore the ways in which Apex code can be invoked in different contexts, the requirements and benefits of those contexts, their commonalities, their differences, and the best practices that are shared. We will distill these into a layered way of writing code that teaches and embeds separation of concerns (SOC) in to the code base from the very beginning. We...