Preface: this post is part of the Write Your First Advanced Trigger series.
Sometimes I feel like this masked dude right here because I give away industry secrets:
Coding is just like magic. The results are spectacular and it’s a great way to get dates (see above)!
But behind all magic is a trick. And once you figure out the trick, anyone can do it!
The biggest secret about Apex is that all triggers are basically the same! Learn to identify the pattern and suddenly coding is no longer secret wizardry – it’s simply a formula with different inputs.
Here’s the secret formula that every trigger follows:
(All examples from this chapter’s trigger)
Folks, every trigger follows this pattern!
Sometimes, you’ll use this pattern twice in the same trigger…
Sometimes, you’ll have a few IF statements in between…
And sometimes, your SOQL query will have another query nested inside it…
…but I guarantee you that your trigger will follow this formula!
Master this formula and you will be a master of Apex magic!
Next post: Intro to Object-Oriented Programming!