
Explore apex triggers from basics to practical use, uncovering context variables, trigger events, before and after triggers, and how to apply logic with guidance from experienced seniors.
Master the prerequisites for Apex triggers by learning DMS (data manipulation language) basics, collections, for-each loops, bulkification, anonymous window, and class and method concepts.
Explore how apex triggers act as event listeners, firing actions on records in Salesforce before or after events such as insertion, adaptation, and deletion.
Explore how Apex triggers listen to object-specific trigger events such as insert, update, and delete, and distinguish before and after variants to run actions before or after a record change.
Learn to create your first Apex trigger in Salesforce via the developer console or setup, understand trigger events on the case object, and verify with system debug logs.
Learn how Apex trigger events control when triggers fire, using before insert, before update, and before delete, and how to print debug statements by aligning events.
Explains Apex triggers and context variables to detect insert operations using isInsert, printing debug logs only for insert while preserving before insert, before update, and before delete trigger events.
Learn to build Apex triggers for update and delete, using isUpdate and isDelete context checks to print debug logs and verify insert, update, and delete paths through hands-on code changes.
Discover how Apex triggers run in two halves, before and after context, using is before and is after variables to track insert, update, and delete with debug logs.
Learn how to implement before insert and after insert logic in Apex triggers by combining context variables like is_before and is_insert with trigger events to print debug logs during insert.
Explore how to use is before and is after in Apex triggers to respond to insert, update, and delete events with per-event logic and debug logs.
Use trigger.new to capture records at save time, handling before and after insert contexts, and iterate the trigger.new collection with a for-each loop to print status.
Discover how to use trigger.oldMap and trigger.new to detect status changes in before update operations, compare old and new records, and log findings.
Explore before context triggers in Salesforce, using validation and preparation of records for insert, update, and delete before they are saved, while no old values or IDs are available.
Demonstrates before insert triggers in Apex by auto-setting priority to high when type is electrical and validating origin phone before save, using trigger context to prepare the record.
Learn to use the before insert trigger to validate and prepare records by checking case origin and supplied phone, throwing errors for incomplete web form data.
Learn to adapt before update logic in Apex triggers by moving insert logic into a separate update block, using the old map to compare records and check origin field changes.
Learn before update triggers in Apex by validating changes to case origin and phone number, using or conditions to optimize logic, and noting data migration for legacy records.
Create a work order automatically when a case is created using after triggers, populating the case ID and subject while using bulkification to insert multiple records.
Use an after update Apex trigger to propagate case subject changes to the related work order, leveraging a case id set and a bulk map for updates.
Learn Apex triggers by updating work orders when a case subject changes. Build a case-to-work order map, verify keys, and apply subject changes in bulk to avoid dml statements.
master apex trigger best practices: one trigger per object, naming, no logic in triggers, use a handler class, bulkify data access, avoid hard coded ids, and asynchronous processing when suitable.
Move business logic from Apex triggers to a handler class, call its methods from the trigger, and use context variables to run before and after insert logic.
Move the before insert logic to a reusable handler class, passing trigger.new records and validating web cases, ensuring the web phone is populated, with placeholders for update and delete.
Move before insert logic to a reusable handler class, implementing a generic method to set high priority for electrical cases across all records, and reuse it for updates.
Move before update logic to a handler class, reuse the existing validation method to check if case origin is web and web phone is null, reducing code duplication.
Convert after insert trigger logic into a reusable handler class, creating a work order from new cases and splitting code into create work order and bulk insert methods.
Learn to move after update logic to a handler class in Apex, splitting into steps: get case IDs, prepare work order map, copy subject to work orders, and bulk update.
Demonstrates common errors in apex triggers and classes, including null pointer exceptions and before insert logic, with debug logs and a reusable approach to update case subjects with high prefix.
Identify and fix apex trigger error 2 by ensuring all used fields are retrieved in the circle query, since the error arises when a field like subject is not included.
Identify and fix error 3 by avoiding queries inside a for loop, which causes too many queries. Use a map or collection instead of in-loop queries in Apex triggers.
Identify and fix the list index out of bounds error in apex triggers by checking list size or emptiness before accessing an index, or wrapping in a try-catch block.
Diagnose apex error 'list has no rules for assignment to this object' by inspecting query results, using debug logs, try-catch blocks, and converting to a list for safe handling.
Trace the final exception read only record by debugging the after insert context, identify the line updating the case description, and move modifications to the before insert context.
Reproduce the maximum trigger depth error in Apex triggers by simulating after update recursion in a Salesforce org. Apply bulkification and move DML to before update to prevent the recursion.
Use a static boolean flag in a utils class to guard Apex trigger recursion, executing the after update block once and flipping the flag to prevent reentry and avoid errors.
Explore why trigger.new lacks parent fields, and learn to query the related account's industry to populate the case description, using bulkified maps and a before insert context.
Explore context variable considerations in Apex triggers, including before and after contexts, trigger.new usage, and using a handler class to keep triggers dumb and reusable across insert, update, and delete.
Identify the triggering point to decide which object to write a Salesforce trigger on, choosing before or after context and insert, update, or delete actions based on user interaction.
Explore why you avoid DML in before context and use after context for external records, clarifying save versus commit with case record and work order as examples.
Master how to retrieve all keys and values from a map in Apex by using keySet and values, and apply this to trigger oldMap and newMap scenarios.
Learn how to implement before delete logic in a Salesforce Apex trigger by using a handler, validating case status with trigger.old, and preventing deletes when status is not new.
Explore how to implement after delete logic in Apex triggers by logging deleted case details to a custom object, capturing case ID, case number, and user ID for auditing.
do I need to write my logic in before context or after context?
On which object do I need to write my trigger?
why do we not write DML on the record that goes through the save process in before context?
What is trigger handler class?
what is before and after context in triggers?
what are context variables in apex triggers and why do we need them?
Hi there, I just shared a few questions that I had when I start my career as a developer. I usually get the same set of questions from the people who are starting their careers as salesforce developers or from the people who are moving to Salesforce from strong Java background.
Let me share a small secret here. Learning Apex trigger needs time and guidance.
It's not you. it is about Apex triggers. you heard it right.
If you ask me why? from experience and understanding, all I could say is. the starting point of Learning of trigger involves multiple points.
yes, we need to learn and keep a track of multiple points at once to get started. Even though you are good with apex. If you are starting with apex triggers you tend to make mistakes.
Let me share my story here. I had written the logic for one of my requirements. Insert scenario was working fine but not the update scenario.
I had wasted half an hour debugging and validating the logic written but I didn't find any reasons why it wasn't working.
You will laugh when you hear the reason why it was not working but trust me it left no stone unturned to figure out the reason.
finally, I admitted the fact that I need some help. I went to a senior developer for assistance, after sharing the requirement and the issue that I was facing. The first question he asked me helped me figure out what was the issue and also pointed out my understanding of triggers.
he asked me, "is the trigger listening to update event?". that's it. His question was my answer. Just by adding the trigger event, my issue was resolved.
I still remember his question. when I begin to write my trigger. :D
when I think back and that incident. I was good with the logic part of the requirement. I failed in terms of technical understanding of triggers/working of triggers.
If I had scared you with the technical terms above. My apologies, I wanted to share my exact story.
As they say, "Every master is once a beginner". I wouldn't consider myself as a master, there is always room for improvement.
I shared this story to let you know that with time and practice things would fall into place.
You will relish your moments when you could help/assist a person who is going through the same struggle.
this course is just that. over my years of experience, I found a way to learn the triggers the easy way. yes, you need to put in some effort but that would be very less compared to debugging my update scenario.
_______________________
How does this course help me?
simple, just by presenting Apex trigger in a presentable way to impress you. :D
To grab the concept, I took the example of a security guard/watchman. After this course, you will realize all these years security guards was teaching these concepts. we just ignored them. Next time when you meet a security guard/watchman, please thank them.
How can you be sure that I can start writing triggers after this course?
once you understand the working of the triggers, you will be in the right space to put your logic into the salesforce org. even though if your trigger is not working, you will know where to look and fix it accordingly.
Disclaimer: A little bit of practice is needed to retain the concepts for a longer time. :) . I can see that look on your face. Yes, I wanted to be realistic. without practice on Day 1, you feel that you mastered it. Week 1, you will feel low on confidence. Month 1, you will rarely remember that you took the time to learn Apex triggers.
why give half a try. if you really want to learn to code.
If you are reading this line. My job is half done. we can talk about the summary of what would you learn in this course.
what are Apex triggers?
what are context variables?
what kind of logic goes in before and after context triggers?
Best practices in apex triggers.
common errors in apex triggers.
confusion with apex triggers.
if you are wondering, I know these concepts. Do I really need to take this course?
I have a simple question for you. are you struggling with the working of the trigger or are you struggling with the implementation of the requirement.
if it has to do with the working of triggers, feel free to check out this course.
if it has to do with the implementation part, couple of points.
1) are you clear with the requirement.
2) is there any limitations from salesforce.