Apex Triggers
I worked on the Apex Triggers module on trailhead. Apex triggers are very similar to database triggers (remember those?). I remember in my first job, which was an enterprise healthcare company, our DB was littered with hundreds of triggers that did various actions whenever records were inserted, updated, or removed.
Triggers are a powerful concept, but tend to be very difficult to maintain at a large scale. Especially when you have a large team. I think they are an artifact of the legacy development methodologies. These days most of the actions that triggers used to be responsible for are managed as either a part of the model, or as separate background tasks.
Despite this being true in most modern software development, Salesforce allows you to write triggers in a first class way that do things when records change. I think this is a case where they are still “ok” to use because they remove a lot of the overhead with having to figure out how to keep track of the state of all of your various records.
The best part about Apex triggers is that unlike DB triggers which require you to write your code in an enhanced variant of SQL, Apex triggers allow you to write the code in Apex. This means that you can take full advantage of all of the built in salesforce libraries, as well as making HTTP callouts (the most powerful part of all of this) in a really simple way.
One thing to note is that if you do make HTTP callouts with Apex, you must do so asynchronously.
Apex triggers have a handy access to the context that fired the trigger, including both the old and new state of the affected object.
One great hint that the module gives us is to write our code to support both single and bulk operations. While most triggers that I have written operate on only a single object at a time; there may come a day when I may want to do work on multiple objects at a time. For example, if I was using the bulk API. By writing the code in a way that supports bulk operations (essentially using a for loop) you can reuse the same code in the future rather than having to handle both cases separately.
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- SQLite DB Migrations with PRAGMA user_version
- Making cgit Pretty
- Using cgit
- My Custom Miniflux CSS Theme
- Convert Markdown to PDF in Sublime Text
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Rewrote my blog with Zine from Drew DeVault's blog
- A eulogy for Vim from Drew DeVault's blog
- Pluralistic: AI "journalists" prove that media bosses don't give a shit (11 Mar 2026) from Pluralistic: Daily links from Cory Doctorow
- Avi Alkalay: Uniqlo T-Shirt Bash Script Easter Egg from Fedora People
- Offline 23 hours a day from Derek Sivers blog
- Pluralistic: California can stop Larry Ellison from buying Warners (28 Feb 2026) from Pluralistic: Daily links from Cory Doctorow
- On Alliances from Smashing Frames
- Acting ethically in an imperfect world from Smashing Frames
Articles from blogs I follow around the net
“Plain text has been around for decades and it’s here to stay.”
There’s a category of “plain text” or “ASCII” diagramming and UI design tools: Mockdown – works immediately on the web, even on mobile Wiretext – works on the web, but desktop only Monodraw – a Mac app I believe these are used by people who prefer intentio...
via Unsung April 24, 2026Pluralistic: A free, open visual identity for enshittification (24 Apr 2026)
Today's links A free, open visual identity for enshittification: No mere poop emoji! Hey look at this: Delights to delectate. Object permanence: RIAA v little girl; Portal turret Easter egg; Atari v indie games; Chabon's Phantom Tollbooth intro; The 0.1%;...
via Pluralistic: Daily links from Cory Doctorow April 24, 2026Nicolas Solerieu
This week on the People and Blogs series we have an interview with Nicolas Solerieu, whose blog can be found at slrncl.com/blog. Tired of RSS? Read this in your browser or sign up for the newsletter. People and Blogs is supported by the "One a Month" club...
via Manuel Moreale — Everything Feed April 24, 2026Generated by openring