Preface: this post is part of the Write Your First Advanced Trigger series.
When faced against impossible coding projects, I remember something my mentor once told me.
Always remember this, it will serve you well during your career!
Anything is possible with code. Remember that even the most complicated programs can be broken down into smaller and smaller pieces, until eventually, every component is simply a true or false decision.
Today I’ll introduce to you this chapter’s trigger and how to apply our simplification strategy to it.
Write a trigger that shares read/write access to an Account with each member of its zip code Territory.
A few notes about this project:
Let’s assume these are the objects and fields available to you:
Now to simplify this trigger, we simply start from the top and break down each possible decision into smaller and smaller pieces until what’s left are basic, easy-to-do code statements.
Even if the entire flow chart looks scary, if you focus on each individual node, it’s a piece of cake!
Really, go through each step and see for yourself!
Also, don’t forget we need to Bulkify these: