- SalesforceChaCha
- Posts
- π Level up your Apex πΊ
π Level up your Apex πΊ
Apex Enterprise Patterns to the rescue π¦Έ
Good morning, Salesforce Nerds! This oneβs for those of you interested in taking your Apex to the next level! π Maybe itβs just for yourself and your own coding adventure. Maybe youβre a lead and youβre searching for a way to get your team to write more maintainable code. Whatever the reason, if you want to write Apex that adheres to both Salesforce development best practices AND software engineering industry standards πͺ itβs time to look at Apex Enterprise Patterns!

Agenda for today includes
Foundations
Level up your Apex
Daily Principle
All the Memes
Foundations
The name of the game is simple: Separation of Concerns (SoC).
Arguably the most important principle in software engineering - separate components of an application into distinct sections that each address a specific concern. π°
Itβs like this, code that is not partitioned properly and is heavily intermixed becomes error proe, a pain in the π to maintain, next to impossible to extend, and hard to learn.
So whatβs a dev to do? We want to write code β¦ but we really want to write βgoodβ code! The π ChaCha πΊ says adopt Apex Enterprise Patterns! This framework will make you think about how you structure your code and force you into applying this principle through 3 distinct layers.
π DISCLAIMER: THEREβS A LITERAL π©-TON OF MATERIAL ONLINE ABOUT THIS. WEβRE JUST GONNA DIP OUR TOES IN HERE AND IβLL LEAVE SOME RESOURCES FOR YOUR NEXT STEPS. HIT UP GOOGLE AND YOUβLL SEE WHAT I MEAN. π
π Resources: Trailhead Intro, Salesforce Platform Enterprise Architecture
Level up your Apex
ποΈ Selector Layer
A layer of code that encases the logic responsible for querying data from SObjects in your org. π§ The selector layer feeds this data into your domain layer and service layer code. These are primed for reuse, too. You can invoke methods on these classes from other any area that require querying. π₯
π Resources: Trailhead Intro, Trailhead Apply
π¦ Domain Layer
With Salesforce Enterprise Patterns, the domain layer is defined through standard objects and the custom objects you create. This allows us to store data. But, now letβs think π€ about the behavior of these objects within the context of our application. Things like validation, calculation, and complex manipulation of data? The best way to think about this layer is that itβs a simple wrapper around a list of records. This is where the domain layer shines! π
π Resources: Trailhead Intro, Trailhead Apply
βοΈ Service Layer
This layer helps you form a clear and strict boundary of code implementing business tasks, calculations and processes. We want to ensure that the service layer is ready for use in different contexts π§ such as mobile applications, UI forms, rich web UIs, and numerous APIs - AKA, this layer should be designed to be caller agnostic. It must remain pure and abstract to endure the changing times and demands ahead of it. π―
π Resources: Trailhead Intro, Trailhead Apply
ππππ BONUS ππππ
π· Unit of Work
The Unit of Work is a design pattern that reduces repetitive code π¨βπ» when recording record updates, inserts, deletes or handing the population of a relationship field between parent/child records. At its core, the Unit of Work maintains a list of objects affected by a business transaction and coordinates the writing out of changes to the database. β€οΈ
Resources: Trailhead Intro, Trailhead Apply
Daily Principle
"Iβm not a great programmer; Iβm just a good programmer with great habits."
and now....Your Daily Memes



What did you think about today's newsletter? |