Salesforce Developer Tutorial - The Complete Guide to Apex Tests in 2024

Salesforce Developer Tutorial - The Complete Guide to Apex Tests in 2024

Coding With The Force

5 месяцев назад

4,997 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@CodingWithTheForce
@CodingWithTheForce - 30.12.2023 09:54

I've realized (despite spending forever making this lol) in this guide I do not specifically cover testing a trigger in Apex. This is because I have become so used to using trigger handler/domain classes over the years that I end up testing the logic in them the exact same way I test a typical apex class! That said, to test an apex trigger, you simply need to do a dml statement that would trigger the trigger. If you have a Case trigger that triggers after update, you need to update a case in your apex test to fire your trigger. If you have a Contact trigger that fires before or after insert you need to insert a new contact in your test class to fire the trigger, etc. This will cause your trigger to fire and will allow you to gain coverage of your trigger. However, if the bulk of your trigger logic is in your triggers, I would strongly suggest moving them to a trigger handler or domain class! It will make your life so much better and easier as a dev! I even have a video covering it :)

Additionally in this video when I describe what happens in a @TestSetup I state that the data is deleted... this was a bad attempt at simplifying the process that takes place. What actually happens is the data is rolled back to its original testsetup state at the end of each test method execution. In more complex testsetup situations I have seen, in the pas,t that testsetup rollbacks end up adding to governor limits, which is why I've mentioned it here.

Ответить
@tornubarikoboo8074
@tornubarikoboo8074 - 05.01.2024 04:39

Great Video!

Ответить
@cmgpguerracarlos
@cmgpguerracarlos - 03.01.2024 04:12

Thanks for all your videos; they really helped me with fflib, and now I understand testing better.

Ответить
@extremeweirdness1528
@extremeweirdness1528 - 02.01.2024 22:01

Hi is there a way to do multiple callouts and set different mocks for each one ?

Ответить
@shashi.shekhar
@shashi.shekhar - 02.01.2024 19:30

We can also consider bulkifying the test methods with bulk test data to check if the code can handle large amount of data (real life production scenario) without failing for exceptions (101/501) etc

Ответить
@CrisjunMarRavelo
@CrisjunMarRavelo - 02.01.2024 18:09

Nice, new Video ❤

Ответить
@richhuynh6314
@richhuynh6314 - 02.01.2024 18:01

First I’m first

Ответить