5 Practice Problems for APEX Triggers

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.

If you have any questions or would like assistance in solving any of these, please comment below or reach out to me at yelena@sf9to5.com.

Problem 1:

Pre-Reqs:

Create a field on Account called “Only_Default_Contact”, checkbox, default off

Assignment:

When a new Account is created, create a new Contact that has the following data points:

  • First Name = “Info”
  • Last Name = “Default”
  • Email = “info@websitedomain.tld”
  • Only_Default_Contact = TRUE

When the Account has more than 1 Contact, update Only_Default_Contact to FALSE.

Problem 2:

Pre-Reqs:

Create a field on Account called “Out_of_Zip”, checkbox, default off

Assignment:

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.

Problem 3:

Pre-Reqs:

Create a field on Contact called Profile, text, 255

Assignment:

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

Problem 4:

Pre-Reqs:

Create a field on Account called “is_gold”, checkbox, default off

Assignment:

When an Opportunity is greater than $20k, mark is_gold to TRUE

Problem 5:

Pre-Reqs:

Create a field on Account called “need_intel”, checkbox, default off

Create a field on Contact called “Dead”, checkbox, default off

Assignment:

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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s