As part of my journey from a “Point and Click Admin” to a “Dev Admin”, I wanted to be able to get more hands-on challenges for triggers than what Trailhead provides. Fortunately for me, I have some very good resources available to me and from such was able to get five different APEX trigger scenarios that are good for any beginner. They are designed to be able to test your ability in understanding how triggers work.
For someone who is more advanced and reading this, please keep in mind that this is merely for the purpose of learning. I would not otherwise advise putting multiple triggers on the same object, with all of the logic living in those triggers. Please see the Salesforce APEX best practices for more information.
Create a field on Account called “Only_Default_Contact”, checkbox, default off
When a new Account is created, create a new Contact that has the following data points:
- First Name = “Info”
- Last Name = “Default”
- Email = “email@example.com”
- Only_Default_Contact = TRUE
When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.
Create a field on Account called “Out_of_Zip”, checkbox, default off
When a Billing Address is modified, get the new Postal Code. Then check which Contacts on the Account are outside that Postal Code. If 1 or more Contacts are outside of the Postal Code, mark Out_of_Zip as TRUE.
Create a field on Contact called Profile, text, 255
When an Account is updated and the Website is filled in, update all the Profile field on all Contacts to:
- Profile = Website + ‘/’ + First Letter of First Name + Last Name
Create a field on Account called “is_gold”, checkbox, default off
When an Opportunity is greater than $20k, mark is_gold to TRUE
Create a field on Account called “need_intel”, checkbox, default off
Create a field on Contact called “Dead”, checkbox, default off
If 70% or more of the Contacts on an Account are Dead, mark the need_intel field to TRUE
Hope these questions help you practice as much as they helped me!