Test kitchen and code recipes for developing on the Salesforce.com (SFDC) platform. No matter what the subject is - LWC, Aura, Apex, unit testing and beyond - the Joys Of Apex has you covered.| www.jamessimone.net
If you had told somebody even last year that Structured Query Language (SQL) was going to be a make-or-break skill for advanced Data Cloud use-cases, I think many people would have laughed. In this rapidly evolving world of development, however, Data Cloud’s strong tie-ins to SQL, has quickly made SQL one of the best and easiest ways to unify structured and unstructured data with disparate sources when answering user queries, Perform fine-tuned RAG using vector_search (and hybrid_search!), ...| www.jamessimone.net
Where you are in the Reduce, Reuse, Refactor series: Interfaces & Object Inheritance (this post) Object-oriented programming languages…| James Simone
Where you are in the Reduce, Reuse, Refactor series: Object Variables (this post) Methods are how objects communicate with one another…| James Simone
Where you are in the Reduce, Reuse, Refactor series: What Is An Object (this post) In , you got a glimpse at the magic of Object-oriented…| James Simone
When in the course of human events it becomes necessary to optimize processes, code has increasingly become the mechanism by which these optimizations are realized. Whereas in the past, a mill might have done the work of dozens -- and in some cases still works in that same function -- code provides an engineer with the tools with which to apply that same savings to an effectively limitless number of corporate & everyday applications. While the term 'digital transformation' has at least in my ...| www.jamessimone.net
Natural language is all the rage these days, and the more Generative AI that we see in our lives, the more important it is that the LLMs behind these AIs are drawing from the right sources. But documents - spreadsheets, text documents, slide shows, call transcripts, etc... -- are typically the place where the 'right' sources live. How can we work to combine document content and ease of access within standard and generative AI-based workflows without creating a tech debt mess, and how can we b...| www.jamessimone.net
It’s been another big year in terms of open source contributions and, as is tradition, I wanted to reflect back on the past year to talk…| James Simone
There are three fundamental tiers of team-based work within organizations; while this article will be focused on improving software engineering teams specifically, many of the thoughts contained within are broadly applicable across industries. The first tier of team-based work happens within single teams, and is limited to the people that make up that team (and how they work together). The second tier occurs as teams inevitably collide - learning to work cross-functionally, perhaps, or with h...| www.jamessimone.net
In the Summer 21 release, finalizers for System.Queueable classes were made generally available. Since then, they've received very little fanfare, despite being one of the most groundbreaking features introduced to the standard platform since Queueables themselves. Let's do a deep dive on why the System.Finalizer interface is amazing, and why if you haven't been using Finalizers on every Queueable, you're missing out!| www.jamessimone.net
When I wrote Dynamic LWC Creation, I had a lot of fun figuring out different ways to bypass the lack of on-platform support for dynamically generated Lightning Web Components. Now that dynamically generating components is GA, I thought it might be fun to revisit things to show off a few of the possible permutations when it comes to making use of this functionality. I'm going to discuss some architectural considerations to keep in mind, as well, and end with a demo of how using dynamic compone...| www.jamessimone.net
The past year and a half has seen AI fervor continue to mount, and for good reason: there exists myriad excellent use-cases for AI within business applications. Because there's so much money -- and so much in the way of vested interest, as a result -- within the AI field, the hype factor has created a problem for those looking to take advantage of LLMs: the signal-to-noise ratio is quite bad. With that being said, I wanted to write a bit about where AI, as it currently stands, really shines -...| www.jamessimone.net
I recently had a request come in on my Refactoring Tips & Tricks article to write more about refactoring; I'm also in the midst of reading the excellent Tidy First? by Kent Beck, which (to paraphrase) defines tidying as a subset of refactorings that you should always do. Sometimes, tidying is as simple as inverting a guard clause to reduce indentation and increase readability. Kent also encourages us, as readers of code, to bridge the gap between us (having just read something) and future rea...| www.jamessimone.net
I've seen a few external guides come and go to authoring SF CLI plugins, but all of the ones I've seen tend to skip over crucial pieces of setup, or to over-install dependencies to get around knowledge gaps. That is, in my opinion, a shame - primarily because authoring SF plugins gives us all the chance to work with TypeScript, which is both a wonderfully expressive language and one that isn't always easy to setup. With that in mind, I want to take you through every single command necessary t...| www.jamessimone.net
It's never too soon (or too late) to test our understanding of programming fundamentals. In this post, I want to explore two very simple benchmarking tests that show how small platform changes can lead to large speed improvements. First, I'll walk you through some code you might remember from Sorting & Performance In Apex to show off how the existing enhancements made to sorting in Winter '24 have led to major sorting performance enhancements. Secondly, we'll take a look at the upcoming suppo...| www.jamessimone.net
In September of 2020, with the COVID-19 pandemic raging globally, I made the decision to start more actively contributing to Salesforce open source projects. Several months later, I open sourced Apex Rollup, and last year added Salesforce Round Robin to the mix. This year has been largely about supporting the growth of both of these projects, as well as continuing to contribute to and support open source classics like Nebula Logger, which appears on track to join the top 5 most-starred GitHub...| www.jamessimone.net
Now that the Slack SDK for Apex is in beta, we have access to a wealth of Slack & Salesforce-based interactions. After spending some time with the SDK, I'd like to provide a broad overview on two areas in which I think there's a ton of potential for us to add value: what I'll be referring to as 'headless' usage of the SDK - interacting with Slack users when the starting point is Salesforce, and interacting with Salesforce data and building out rich bot-based experiences within Slack. Both of ...| www.jamessimone.net
It's common when discussing software engineering to encounter the phrase 'decoupling.' I've talked about it in over ten articles on this site alone 😅. Decoupling itself is really a nod to one of the SOLID principles -- namely, dependency inversion or the idea that objects shouldn't be 'strongly coupled,' instead relying on 'loose coupling' where objects take in dependencies that are as abstract as possible. Why does this matter? Why should we consider how strong or loosely coupled the obje...| www.jamessimone.net
Large language models have swept the world with a fervor last seen when the internet itself first began to pervade everyday life. And generative AI itself is positioned to create an entirely new category of applications... How we, as developers (and the people working with developers) model our systems has _never_ been more important.| www.jamessimone.net
I was reflecting on a week filled with deploys last night and thought there was an interesting takeaway about two different instances of scope creep - and the two _very_ different outcomes we as a team ended up with in two of our applications. It's a story where you as the reader get to decide at the end of the day what the takeway is. I'll be interested to hear if you end up with the same takeaway that I did.| www.jamessimone.net
Working with TypeScript is an incredible experience - and one that I can't recommend highly enough for anybody who feels like they're starting to get comfortable with JavaScript. In this post, I'll review how working with TypeScript and SFDX can be mutually beneficial. Whether your goal is to use SFDX within CI/CD, extend the functionality of the CLI in ways that you don't see being broadly reshareable, or within the context of something like a GitHub Action, you can benefit from using TypeSc...| www.jamessimone.net
Last year, I wrote about A Year In Open Source, and I wanted to wrap this year up with another reflection after having hundreds of hours over the course of 2022 engaged in giving back. I've had the pleasure of mentoring colleagues & friends; of contributing additions to popular open source libraries like Nebula Logger, Trigger Action Framework as well as my own repositories; of reading and continuing to hone my own skills. I was also a guest speaker at an internal symposium for Open Source we...| www.jamessimone.net
There comes a time in every Salesforce implementation when the native lead conversion functionality needs to be extended. Most frequently, this is the result of needing to perform lead conversion in bulk. Lead conversion tends to be a slower process, and an unbulkified process runs the risk of timing out. This makes sense - the worst case scenario involves a contact, account, and opportunity being created, as well as the lead being updated. That's a lot to take care, under the hood! Let's div...| www.jamessimone.net
I was on the Salesforce developer podcast talking about speed versus quality (https://developer.salesforce.com/podcast/2023/03/episode-167-move-fast-dont-break-things-with-james-simone) a few weeks ago, and I'd encourage you to give that conversation a listen if you haven't already because it sets the stage nicely for this article. The theory that baking quality in from the get-go begets speed was the basic premise, but I've seen the opposite of that play out over and over again in software e...| www.jamessimone.net
Jonathan Gillespie writes about caching data in Apex, and how to leverage static variables & platform cache to build a caching management system that can help improve the performance of your Apex code| www.jamessimone.net
Lightning Web Components (LWCs) have become the de facto standard when it comes to frontend development on the Salesforce platform. They're a massive step above the prior framework, Aura, in terms of quality, idiomaticness, and testability. Most people aren't looking for Aura to make a comeback. That being said, there are a few things we've had to sacrifice, or wait for, as the LWC framework has matured - modals were an obvious example of this (I wrote about this in LWC Composable Modal), tho...| www.jamessimone.net
Lightning Web Components (LWCs) have been around on the platform for five years, but I still see rudimentary questions about testing LWCs constantly. This article will attempt to start slow before deep-diving on interesting topics for those looking to level up their frontend unit testing chops| www.jamessimone.net
I recently revised the original Factory pattern article, and wanted to write a follow-up after a few years' spent reflecting on its usage within Apex. In particular, I'd like to talk a little bit about the Singleton pattern, and how with a small amount of work we can enhance the existing Factory class in order to gracefully create cached instances of classes where a large amount of work goes into constructing them.| www.jamessimone.net
Join guest author Kai Tribble as we further explore the topic of CI/CD, or continuous integration and continunous delivery. In his own words: it's no secret in the Salesforce developer community that a constant struggle exists within the migration of code written in a sandbox environment to Production. As Salesforce engineers, we've been given a variety of toolsets including Change Sets, ANT, and more-recently, SFDX to simplify and automate migrations. Highlighting the latter, I'd like to div...| www.jamessimone.net
Open source work is an incredible way to build up a corpus of referenceable work when applying to jobs, but there are other reasons you might want to build up a portfolio of Apex-related code. Learning how to package and distribute code, for example, or giving yourself the chance to show off a piece of functionality you're particularly proud of.| www.jamessimone.net
Want to improve yourself as an engineer? Looking for tips & tricks to empower yourself as a teammate or individual contributor? There are a few things that you can do at any point in your career that will help. There's a reason that professional athletes frequently preach the importance of fundamentals - while it may seem like common sense, now, it's only been recently through the application of science to sports that experts have begun to understand how practice quite literally makes perfect...| www.jamessimone.net
Following up on the Object-Oriented Basics post, this time we switch our attention to interfaces and abstract classes - when to use them, when to avoid them, and how to distinguish between them. Learn all about what makes an interface successful, how to consolidate logic in abstract classes, and more!| www.jamessimone.net
There are a few limitations when it comes to the History records created by default when Field Level History is enabled for an object, not the least of which is history records not being created in tests. This can make testing logic out that employs History records difficult to approach, especially from a Test Driven Development standpoint - but it doesn't need to be so hard. Join me as we walk through how to setup an easily reuseable implementation for mocking History records and retrieving ...| www.jamessimone.net
I decided to open source my Salesforce round robin assigner because I know how difficult it is to get the edge cases right when building something like this, and I wanted to create an easier way to hook into round robin-style assignments for both Flow and Apex developers. I'll walk a little bit through the changes I made prior to packaging up this functionality, and hopefully leave you with another great free tool.| www.jamessimone.net
One of the best thing about using strongly typed query builders is the type-checking that you get -- for free -- while using them. Type-checking not only prevents you, as a developer, from making a mistake -- it also prevents admins from updating the API name for a field or from being able to delete it while it's referenced within your Apex code. Even if there were no other use for the `Schema.SObjectField` class, those two reasons alone would make it worth our while when deciding when to use...| www.jamessimone.net
Deep Work - the concept of blocking out prolonged sections of uninterrupted time to do work - has been making the rounds in tech circles the past few months. On the other side of things, we have mob programming, which focuses on something that seems completely contradictory to the Deep Work movement -- working collaboratively throughout the day while on a video call, with only one person typing at any given time. Whereas Deep Work focuses on people achieving flow state by having lots of solo ...| www.jamessimone.net
At the end of 2020, I decided to take 2 weeks off of work at the end of the year. I was very fortunate to be able to do so, and I found myself in the position of wanting to give back. I'd had to replace DLRS within the org for the consulting company I was working for several months previously, and the idea of creating a more performant rollup engine was an alluring way to do so. The simple `RollupCalculator` class I'd made seemed just a _few_ lines away from a much simpler implementation than...| www.jamessimone.net
Assignment, be it for Leads, Cases, or custom objects in Salesforce, doesn't always conform to out-of-the-box offerings. I've seen a few places where OmniChannel didn't quite align with a company's business rules; where Lead Assignment Rules didn't offer the capabilities necessary to properly assign an owner. One common example of this is the so-called 'round robin' assigner, where a company's leads (or any other object) need to be assigned fairly between a number of sales reps. In this artic...| www.jamessimone.net
Learn about some of the latest features made to the Nebula Logger project over the last 8 months to further improve Salesforce logging capabilities.| www.jamessimone.net
Structured Query Language (SQL) and the basic Salesforce equivalent, SOQL, share many commanalities. Each has the ability to pull data back from the database through the use of specialized keywords. SOQL has many peculiarities, not the least of which are the limits the aspiring developer is under when using it. What may seem like one of the best features of Apex -- its seamless integration with SOQL -- is, however, unusable when it comes to producing truly dynamic and flexible queries. As wel...| www.jamessimone.net
You've heard about the joys of using platform events from Jonathan in Advanced Logging Using Nebula Logger - their versatility and interoperability with exception handling being a primary example of where the two features dovetail nicely together. Something interesting starts to occur when your platform events start firing other platform events, especially when those platform events originate from Apex that is already running asynchronously| www.jamessimone.net
I'd like to take you through a routine refactoring exercise to showcase the power that objects wield when used correctly. This is, in my opinion, the single most _satisfying_ refactoring, because it showcases how maintanability improves by fixing an improper abstraction instead of letting it fester. This exercise will also highlight a curious junction between Test Driven Development (TDD) and Domain Driven Design (DDD) - which is to say that if the functionality that you're working to refacto...| www.jamessimone.net
Flows are increasingly a part of the Salesforce automation picture, and their seamless melding with Apex through invocable Apex is part of the reason why admins and developers alike are embracing Flow. Learn how easy it is to make simple, reusable Apex invocables, taking advantage of patterns to avoid tight coupling and code duplication.| www.jamessimone.net
My manager and I met up the other morning for a paired programming session. We had two possible things to work on and decided to embrace Kent Beck's 'start small, or not at all,' by focusing on a seemingly innocuous task -- adding the disabled attribute to a lightning-button in one of our Lightning Web Components (LWC). Even with strict adherence to TDD, this is a task that should take only a few minutes; it's not a complicated component, and the change is extremely straightforward. Would it ...| www.jamessimone.net
Learn how to implement the Nebula Logger project for Salesforce for advanced logging, and some of the challenges experienced over the years with implementing a custom logging tool.| www.jamessimone.net
We owe our ability to understand abstractions in programming to philosophy; much as we owe a debt to mathematics for putting the theorems responsible for our code -- and computers -- to work into words. Consider the immortal words present in the Tao: A well-shut door will stay closed without a latch. Skillful fastening will stay tied without knots. One does not simply (walk into Mordor) build a door that works well. A factory for doors cannot provide you with the quality of worksmanship and p...| www.jamessimone.net
Expressing intent through naming is a challenge, but well-named methods can help to expose even the most complicated of programming mechanisms. In programming, as in life, context is key - let's explore how naming can elevate the intent and rationale behind code! Whether you're just beginning your programming journey or you're a veteran programmer of many years, it's my hope that there's something in this post for everybody.| www.jamessimone.net
A few months ago I was tasked with replacing Declarative Lookup Rollup Summaries (DLRS) in an org suffering from frequent deadlocks. Rollup summary fields in Salesforce are plagued by severe limitations -- only being available on master-detail relationships being just the start of the list. Read on to learn about how I built Rollup to assist in orgs looking for DLRS-like flexibility with a much smaller performance overhead, complete with elastic scaling (go fast when you need to, slow when th...| www.jamessimone.net
Learn how to implement the Fisher-Yates / Knuth random sort or shuffling algorithm in order to select random elements out of a list in this entry from the Joys Of Apex. Revisit some older code and watch as it gets spruced up with the help of algorithms and hindsight to produce a better version than existed previously. How often do you revisit old code?| www.jamessimone.net
Calculating time differences correctly is challenging. With more than two dozen time zones at play on any given day around the world, and yearly / historical fluctuation in time, it's no wonder that Salesforce stores dates in GMT and tries to enforce good practices surrounding time and date calculation by giving you -- the developer -- quality date/time APIs when dealing with them. When working with formula fields in Apex, however, the developer must keep in mind certain idiosyncracies in ord...| www.jamessimone.net
Custom Permissions changed the game when it came to creating programmatic checks for feature management within Salesforce. Between Custom Metadata and Custom Permissions, Salesforce as a whole has been trying to gently move people away from permissions management by way of hierarchical custom settings. And there's a lot to love when it comes to Custom Permissions, in particular. Since Winter '18, the FeatureManagement.checkPermission method has enabled developers to easily implement permissio...| www.jamessimone.net
Don't prematurely optimize. It hurts, sometimes, to look at code that we know could be refactored to read better -- and you should clean up such code whenever you can. Learn about the XY Problem and why sometimes, the issue that you're looking to solve goes deeper than just an ugly piece of code.| www.jamessimone.net
Setting delays programmatically within Apex represents a unique challenge. We don't have access to the current thread instructions that are being carried out, nor do we have any kind of higher-level `delay` function. While this is frequently fine for internal usage, where the last thing you would want is for your compiled code to be slow, that's not always the case when interacting with external APIs. It's common for APIs to be 'rate-limited' - go over the number of requests you're supposed t...| www.jamessimone.net
Identifying areas for potential code reuse is not always obvious. People learn and remember things in different ways; on a large team, and in a large project, keeping the entirety of a code base in your head is frequently an improbable proposition. Some manage. Some find themselves rewriting functions monotonously, either on a tight sprint deadline or simply because it’s easier to copy paste than it is to generalize. Refactoring is, ultimately, a luxury - but one that is worthwhile to inves...| www.jamessimone.net
Learn how to use Lightning Web Components and the composable modal to create a custom Path component within Salesforce. We cover fetching/updating data with Lightning Data Service (as well as how to deal with dependent @wire requests with LDS), accessibility, and more on the road towards grouping Closed lead statuses.| www.jamessimone.net
Continuation of the previous post on Lightning Web Components (LWC) and the composable modal. In this post, we dive into some major improvements to the modal thanks to community contributions throughout the weekend, looking in particular at how focus-trapping has been improved, as well as a deep-dive into the subject of testing Lightning Web Components using sfdx-lwc-jest.| www.jamessimone.net
Continuing on the LWC train from our talk on [pagination](/blog/joys-of-apex/lwc-composable-pagination) comes this post on creating a reusable modal, or pop-up, as a Lightning Web Component. Modals, by themselves, have complicated requirements for both accessibility and UX; they must block-off the rest of the screen, for example. It's good practice for a modal to control the page's focus until it is closed. How can we build a composable modal, or one whose implementation is not tied to the ex...| www.jamessimone.net
Learn how to paginate properly in LWC, and unlock the potential of composable Lightning Web Components in the process. Composition over inheritance is one of the most crucial concepts in Object-Oriented Programming, but the Lightning Web Components documentation doesn't give newer developers enough in the way of resources when it comes to building a complicated, reusable component - exactly what we'd like to do when implementing pagination.| www.jamessimone.net
So-called Lazy evaluated functions have their actual execution delayed until a terminator function is called. It's common for lazy functions to be chained together using fluent interfaces, culminating with actions being performed when the terminator function is called. What can Salesforce developers writing Apex code stand to gain by learning more about lazy functions? Fluent interfaces -- or objects that return themselves during function calls -- also tend to satisfy one of the prerequisites...| www.jamessimone.net
This series has spent quite a bit of time talking about Test Driven Development (TDD), and has shown many examples along the way. Now I'd like to take a step back; to return to the roots of TDD, both to show why it can be such an effective development strategy, and also to review the fundementals. Test Driven Development is guided by the belief that your tests should be self-documenting; that they should be the best place for a new developer to start learning the code base, by assimilating th...| www.jamessimone.net
Updating your build pipeline to use SFDX is something that is coming up with greater and greater frequency. Many companies are still using the old metadata format for Salesforce, and perhaps the full advantage of scratch orgs and the new metadata format is still a hard sell. It's understandable. Using ANT, jsforce, or any of a dozen other legacy options for performing production deploys makes people uncomfortable; also understandable.| www.jamessimone.net
The Singleton pattern is frequently used to represent objects that should only be initialized once; either because in being constructed, they feature CPU intensive operations, or because they revolve around atomic operations (like logging a specific time) that should always be referenced consistently. Learn how to improve upon the idiomatic Apex singleton pattern in Salesforce to reap performance benefits and save lines of code at the same time!| www.jamessimone.net
Picklists in Salesforce replace traditional HTML select fields on the front end. They also are driven by complex metadata types that we don't have programmatic access to in our code. I'll discuss one potential approach to strongly typing a picklist's values based on describe results and a little boilerplate.| www.jamessimone.net
Batchable and Queueable Apex are both powerful processing frameworks within Salesforce. Unlock the power of both Batchable and Queueable Apex with the easily extendable DataProcessor pattern.| www.jamessimone.net
Learn more about performance testing the CRUD framework, the cost of sorting, and how to implement custom sorting easily.| www.jamessimone.net
Learn about Apex from the ground-level upwards: the basics of object-oriented programming, static types and type inference, virtual and abstract classes, interfaces, polymorphism, encapsulation and inheritance.| www.jamessimone.net
Comparing Salesforce Lightning Web Components (LWC) to React.js in terms of boilerplate, composition, and performance.| www.jamessimone.net
API development in Apex is mostly bespoke, requiring the duplication of rest resources. Let's look at how we can change that using inheritance and polymorphism to power our routes. Using extendable, dynamic APIs give us a huge amount of flexibility in spinning up new HTTP routes within the /apexrest/ path, letting us write code that external teams can stress-test and experiment with faster.| www.jamessimone.net
The abstract enum class in Apex can be very helpful as a class-like object, but there are a few things you should keep in mind to avoid getting bitten by the use of enums.| www.jamessimone.net
Structuring your unit tests to run fast in Salesforce's Apex programming language is crucially important when designing large systems, allowing you to quickly iterate and successfully refactor.| www.jamessimone.net
Tap into the power of the Trigger Handler pattern in Salesforce with this extremely lightweight Trigger Handler framework.| www.jamessimone.net
We often hear the word idiomatic applied to programming languages to express the language-specific way of accomplishing routinely encountered problems. In this post, we dive into how to write idiomatic Salesforce Apex to make the most of each line of code.| www.jamessimone.net
Synchronous apex methods typically use asynchronous future methods to perform API calls, or callouts in Apex. This article covers the best way to execute performant HTTP-related code, while allowing for further processing to be done. It makes use of the Queueable interface in Apex, and shows how to implement the Queueable interface with the least amount of boilerplate.| www.jamessimone.net
Learn how to use Repositories to protect your SOQL usage and easily swap implementations in unit tests| www.jamessimone.net
Surfacing Apex exceptions through a dedicated logging platform so that exceptions in your Salesforce code can be easily monitored.| www.jamessimone.net
Dependency injection is a crucial method for correctly initializing & testing objects, and the Factory pattern can help to standardize how your SFDC Apex objects are produced| www.jamessimone.net
Cover the basics of mocking DML operations through the use of a DML class that can be swapped in unit tests.| www.jamessimone.net
Dive into the philosophy behind unit testing in Apex, and why writing good tests is so important.| www.jamessimone.net
Our team has had an insanely productive past three months. We've consistently cruised past goals, exceeded expectations, delivered new functionality, and had fun doing so. How did we do it? How can we keep the momentum going? Here's what it comes down to: teams perform well when successes are shared and failures are owned.| www.jamessimone.net