πŸ’ƒ 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. 🎌

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. ❀️

Daily Principle

"I’m not a great programmer; I’m just a good programmer with great habits."

Martin Fowler

and now....Your Daily Memes

What did you think about today's newsletter?

Login or Subscribe to participate in polls.