Salesforce Developer Tutorial: How to Implement a Trigger Framework

  Рет қаралды 10,542

Coding With The Force

Coding With The Force

Күн бұрын

Пікірлер: 24
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
For some reason I just kept wanting to say, "Trigger Handler Framework" in this video... It's just a "Trigger Framework". I'm sorry my brain just couldn't stop feeding me those words. It's just a Trigger Framework.
@marvtheandroid
@marvtheandroid 4 жыл бұрын
Thanks, super helpful to see these practices in action. I was given one sample trigger framework before and it had way too many layers of abstraction. Looking forward to more videos like this!
@FrenchyRider574
@FrenchyRider574 Жыл бұрын
Thank you !
@coolboy5470
@coolboy5470 4 жыл бұрын
Why dont you make a video for how we can use OOPs concepts in apex and best practices in apex with live examples
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
That’s a great idea! I will definitely add it to the list. Thanks Ashutosh.
@iulianachiriac3623
@iulianachiriac3623 Жыл бұрын
Thank you very much for all your videos. They are very helpful.
@salesforcetutorialsbybill4148
@salesforcetutorialsbybill4148 4 жыл бұрын
Any reason you prefer this framework over one that uses a Custom Metadata setting to control the execution of Apex?
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
You can very easily add that to this framework. In fact I have a version of the code that does it in about 5 lines of code if you are interested. I actually prefer utilizing custom settings for this instead of custom metadata (if you're talking about turning the trigger on and off by flipping a switch or based on a running user). I have a video explaining why I prefer custom settings if you're interested: kzbin.info/www/bejne/m6C3mpKJhrqdppY&ab_channel=CodingWithTheForce
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
To further elaborate on the question though. This framework is just super simple and easy to understand and it's also very flexible. I've tried using 5-6 different frameworks and this one was the easiet to implement, the easiest to teach developers, allowed me to easily add whatever I needed and it gave me all the core benefits of a typical trigger framework.
@muhammadkhattak1573
@muhammadkhattak1573 3 жыл бұрын
Very helpfull thank so for the help
@chethelesser
@chethelesser 3 жыл бұрын
Aiight, first of all, thank you for your content! It's of the highest quality compared to the competition in regards to both topics and delivery. I want to discuss the "Why?" points because I was asked this at an interview, and didn't answer so great repeating the usual stuff that's listed on the web on this topic. So here's my 5 cents. 1. "If you put your logic in the trigger, it becomes hard to unit test that logic." I'm on the fence about this. I don't really have a good argument for it, but I'd rather test DML operations and not trigger handler methods. Kinda because it's closer to the actual use case. As for helper methods - you can use them inside the trigger, with no handler class as a mediator. So there's no difference in that regard whether you put your logic inside the trigger or not, it's a matter of how you organize your tests. 2. Reusability. I find this unrelated. Again, put the reusable parts in helpers/utilities and reference them right inside the trigger. No difference whether you're using a handler or not. 3. Readability (nice, modular, beautiful-looking code). Yep. No objections. What I don't see mentioned is by using a handler inside a trigger you get to choose system vs user mode. Trigger always executes in system mode, while you can write a with sharing handler, and that's easily an equally important reason as reusability and readability in my opinion.
@russellcopeland6487
@russellcopeland6487 3 жыл бұрын
The Trigger Framework is perfect for a use case I'm facing. Is there a similar concept of a Validation Rules Framework that I can use to bypass Validation Rules?
@CodingWithTheForce
@CodingWithTheForce 3 жыл бұрын
Hey, I’m sorry for the late response, I must’ve missed this comment somehow. You can actually use this exact same tactic to create validation rule switches. In fact, I think (maybe) at some point I briefly mention that in the video. Here’s a pretty good article explaining how to achieve that in validation rules: salesforceprofs.com/hierarchy-custom-setting-in-validation-rules/
@russellcopeland6487
@russellcopeland6487 3 жыл бұрын
@@CodingWithTheForce not late at all! I watched the video when you first released it and have a need for it now. Thanks for the validation rule suggestion, I will try that out.
@marikenafeuereisen5338
@marikenafeuereisen5338 2 жыл бұрын
Great video as always! I still have this confusion, in which scenarios to use Trigger "isBefore" and "isAfter"
@kenwilson8415
@kenwilson8415 Жыл бұрын
I tend to use isBefore if I want to make direct updates to the record that initiated the trigger. I use isAfter if I want to do something to other records (child records, parent records, completely unrelated records).
@russellcopeland6487
@russellcopeland6487 4 жыл бұрын
Very cool. I will look into this for my own projects. Have you ever used a Logger Framework? Logging has been a pain point with Salesforce and I've wondered if Logger Frameworks could help.
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
Thank you so much! I definitely have investigated them. This is my favorite logger framework personally, I plan to do a video on it eventually, but it is excellent and makes life quite a bit easier when logging: github.com/rsoesemann/apex-unified-logging
@stevenduong8126
@stevenduong8126 2 жыл бұрын
That is awesome. Thanks so much,Sir.
@clydetan7731
@clydetan7731 4 жыл бұрын
What if in a scenario where you want to do something in both after insert and after update? would you need to override both afterInsert() and afterUpdate() in the handler?
@clydetan7731
@clydetan7731 4 жыл бұрын
I mean, that's going to be 2 method in 1 class calling the same logic from a utility class. Or is there any way to do it in a single override method?
@CodingWithTheForce
@CodingWithTheForce 4 жыл бұрын
@@clydetan7731 If you wanted to do that, what I would suggest is making another virtual method in the TriggerHandler class called "AfterActions" or something and have it called in the run method for both afterInsert and afterUpdate triggercontexts. Then you can override that virtual method in your class and only call it instead of the individual afterInsert or afterUpdate methods. Hopefully that makes sense.
@clydetan7731
@clydetan7731 4 жыл бұрын
@@CodingWithTheForce thank you
@aalailasafouane1067
@aalailasafouane1067 11 ай бұрын
very helpfull
Salesforce Developer Tutorial - The Complete Guide To Apex Triggers in 2022
2:09:40
路飞做的坏事被拆穿了 #路飞#海贼王
00:41
路飞与唐舞桐
Рет қаралды 26 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 66 МЛН
Подсадим людей на ставки | ЖБ | 3 серия | Сериал 2024
20:00
ПАЦАНСКИЕ ИСТОРИИ
Рет қаралды 554 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Trigger Action Framework
1:13:26
Salesforce Apex Hours
Рет қаралды 16 М.
Salesforce Developer Tutorial (LWC) - The Complete Guide to LWC Lifecycle Hooks
45:56
Salesforce Developer Tutorial: How and When to use Interfaces In Apex
54:18
Coding With The Force
Рет қаралды 7 М.
Salesforce Developer Tutorial (LWC) - The Complete Guide to LWC Jest Tests in 2023
2:16:25
OAuth 2.0 and OpenID Connect (in plain English)
1:02:17
OktaDev
Рет қаралды 1,8 МЛН
A History of Clojure by Rich Hickey with Q&A
1:07:02
Visas Meilas
Рет қаралды 31 М.
Salesforce Developer Tutorial - How and Why to use Scratch Orgs for Development
1:00:52
Salesforce Developer Tutorial - The Complete Guide to Apex Tests in 2024
1:45:37
Coding With The Force
Рет қаралды 8 М.
路飞做的坏事被拆穿了 #路飞#海贼王
00:41
路飞与唐舞桐
Рет қаралды 26 МЛН