
Explore apex triggers, including before and after contexts, bulk processing, and the order of execution, through a 30-use-case live coding series.
Write a before insert trigger on the task object to set each new task's priority to high using trigger.new, illustrating bulk-safe updates before save.
Create a before update trigger on the lead object to automatically set the lead status to working contacted for updated records by iterating over trigger.new and updating lead status field.
Set case priority in a before insert trigger: if the origin is phone, assign high; otherwise assign low. Note that this logic runs only on insert, not on updates.
Demonstrates a before update apex trigger on the lead object that, when industry is health care, sets lead source to purchased list, cc code to 1100, and primary to yes.
Use case five updates the opportunity stage to closed one via an after update trigger on the opportunity object to create a task for the owner to split revenue.
After a lead is created, this use case uses an after insert trigger on the lead object and a handler to create a follow up task for the lead owner.
Use case seven shows a before update trigger on the opportunity that updates the amount based on probability times expected revenue, using trigger.old/trigger.new and map variants to detect stage changes.
Prevent creating a contact without a parent account by using a before insert trigger, throwing an error with addError to enforce parent information as mandatory.
Block ownership changes on accounts when industry is agriculture and type is apparel with before update apex trigger. Use trigger.old and trigger.new to detect changes and addError to stop updates.
Write an after update trigger on the account object to propagate account website changes to all related contacts, updating their website fields.
learn to create multiple contact records from an account using an after insert Apex trigger, driven by a create contacts field and linked to the account.
Uses a before delete trigger on lead to block deletion when status is working or contacted, using addError, referencing trigger.old, and debugging to align API values.
After delete on the opportunity triggers the creation of a follow-up task assigned to the opportunity's account owner, with high priority, not started, and a description to investigate the deletion.
Create a before insert trigger on the contact object to detect duplicates by last name, email, and phone, and use addError to block creation when a matching record exists.
In use case 15, after updating an opportunity to closed lost, automatically remove opportunity team members by querying and deleting their records in an after update trigger on the opportunity.
Use case 16 restricts case deletion to the system administrator. A before delete trigger uses user info to verify profile equals system administrator and throws an error for non-admin deletions.
Use case 17 creates a contact, then an after insert shares it with the Contact Innovators public group via a contact share record with read or edit access.
After an opportunity update, add all active opportunists to the opportunity team when the stage becomes needs analysis.
use case 19 increments a contact's number of tasks associated whenever a new task is created and assigned, implemented via an after insert trigger on the task object.
Use case 20 implements a contact after update trigger that sends an email to the account owner when a contact's email or phone changes, for accounts with an active parent.
Copy the parent account's billing address to the contact's mailing address during before insert, using a map of account IDs to populate city, state, country, street, and postal code.
Use case 22 enforces updating a task only if the parent account's modified task permission checkbox is checked, by a before update trigger that traverses whoId to account via contact.
Enforce the max contacts allowed rule on accounts by creating a max contacts allowed field and implementing a before insert trigger on contacts to block excessive insertions.
Learn how a single Apex trigger syncs contact locations on field changes. The approach handles insert and update, using Trigger.new and Trigger.old to adjust related records.
Explain the after update use case that notifies owners, team members, and Megastar public group when an opportunity closes by sending emails using a template.
Set the account's sales rep field to the owner's name during before insert by mapping account IDs to owner IDs, querying users, and populating the field on create.
Implement a before update trigger to prevent editing leads created more than eight days ago, enforcing an error when the creation date is older than eight days.
Use case 28 creates an after update reminder task for the opportunity owner when the stage moves from perception analysis to qualification or prospecting, scheduled for tomorrow.
Restore an account from the recycle bin triggers an after delete event, and the trigger queries accounts to prefix the restored name with 'restored' before updating.
Update related contacts' lead source to phone when an account's industry changes to biotechnology, using an after update trigger and a future method to handle async apex and governance limits.
Apex Triggers are one of the most important tools in a Salesforce developer's toolkit — but if you've only seen basic "insert a record" examples, you're missing the real skill: writing clean, bulkified triggers that hold up in production.
This course walks through 30 real-world use cases covering before-triggers, after-triggers, trigger context variables (new, old, and isInsert flags), and the business logic patterns you'll actually be asked to build on the job — from cross-object field updates to preventing duplicate records to enforcing validation logic a simple validation rule can't handle.
What you'll learn:
The difference between before and after triggers, and when to use each
How to properly bulkify trigger logic so it doesn't break on batch updates or data loads
How to work with trigger context variables and understand trigger execution order
30 practical, job- and exam-relevant use cases you can adapt directly into your own org
Common trigger mistakes that cause governor limit errors, and how to avoid them
Who this course is for:
Salesforce developers who want to move past toy examples and write production-quality trigger code
Admins transitioning into development who need a solid grounding in Apex automation
Anyone preparing for a Salesforce Developer interview or certification exam
By the end of this course, you'll be able to design, write, and test Apex triggers with confidence, and explain your design choices in an interview or code review.