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

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 25

  • @CodingWithTheForce
    @CodingWithTheForce  Před 8 měsíci +13

    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.

    • @diobrando1253
      @diobrando1253 Před 8 měsíci +1

      I’m glad I found out your channel ❤ thanks for the videos hope you keep posting and us keep learning from you

    • @luisescalante4897
      @luisescalante4897 Před 6 měsíci

      Thank you so much for making this video Matt, I have found it very helpful! Just a quick question, so, if we are using DataFactory, we will use it in the @TestSetup? Or DataFactory methods can be used directly inside of the test methods?

    • @CocoricoFlux
      @CocoricoFlux Před 5 měsíci

      Hello Matt, thank you for all your video, I'm getting to understand Apex !
      I'm halfway through the video but the part about testsetup was surprising for me. I worked for an ISV where our devs struggled to make some test because we had a ton of data to create beforehand and I was thinking: "maybe they should have split their test in multiple classes with the same test setup".
      You already corrected it in your comment but I would like to emphasize that the test setup run only once and only rollback between test if necessary.
      Here is the paragraph from the Salesforce documentation "If a test class contains a test setup method, the testing framework executes the test setup method first, before any test method in the class. Records that are created in a test setup method are available to all test methods in the test class and are rolled back at the end of test class execution. If a test method changes those records, such as record field updates or record deletions, those changes are rolled back after each test method finishes execution. The next executing test method gets access to the original unmodified state of those records."

  • @iamTHIEN013
    @iamTHIEN013 Před 3 měsíci +1

    This guy is a God among Safeforce dev, I'm so grateful. Thank you so much

  • @NachoYT134
    @NachoYT134 Před 4 měsíci +1

    This is a real masterclass. Thank you thank you thank you!!

  • @cmgpguerracarlos
    @cmgpguerracarlos Před 8 měsíci +1

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

  • @assiabensaada1852
    @assiabensaada1852 Před 7 měsíci

    i press like button even before watching your video! i'am starting my journey soon as a salesforce developper in Paris thank you !

  • @shashi.shekhar
    @shashi.shekhar Před 8 měsíci

    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

  • @shaunvanhuyssteen7966
    @shaunvanhuyssteen7966 Před 7 měsíci

    Heya Matt, this is fantastic thanks man!
    I still need to go through the whole video but getting testing right is something that we've been struggling with in our team so getting a good idea on best practices will help a lot!
    I was also wondering, do you have any recommendations on resources where a developer can learn more about AI in Salesforce? Everything I've seen, including the AI associate, seems high level. I would love to learn how to implement custom NLP models and LLM in Salesforce

  • @levon9
    @levon9 Před 8 měsíci

    Very helpful. I just ran the first test, and I noticed that my output table (?) looks different from yours at time 16:00. I don't have the "CLASSES" "PERCENT" "UNCOVERED LINES". Instead I get a summary that has two columns, NAME and VALUE which shows some information (incl Pass Rate 100%). Just curious why my output would be different. Win 10 with latest version of VSCode.
    Thank you so much for making this video. I've already picked up some useful information & reminders in the 16 minutes I've watched, looking forward to the rest.

  • @ranjithshastry9961
    @ranjithshastry9961 Před 4 měsíci

    Hi @CodingwithTheForce can i Please know the lwc master series which your planning which i saw in one of the vedio could you please let us know when your Planning to upload Eagerly waiting,Thank you!

  • @DaDudeMan
    @DaDudeMan Před 6 měsíci +2

    LWC masterclass when?

  • @pedroprada1
    @pedroprada1 Před 4 měsíci

    great trainign!

  • @SalesforceWithTK
    @SalesforceWithTK Před 8 měsíci

    Great Video!

  • @CrisjunMarRavelo
    @CrisjunMarRavelo Před 8 měsíci

    Nice, new Video ❤

  • @sheddy3561
    @sheddy3561 Před 5 měsíci

    My man switched to VS Code😀

  • @user-wt8xb6jj2h
    @user-wt8xb6jj2h Před měsícem

    U are epic

  • @extremeweirdness1528
    @extremeweirdness1528 Před 8 měsíci

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

    • @wslee00
      @wslee00 Před 8 měsíci

      have your mock hold a list of responses and pop each one out as callouts are made

  • @CloudCodeInsights
    @CloudCodeInsights Před 7 měsíci

    Is there anything in documentation that outlines that test setup runs per each test method? I tested in a dev edition and I'm only seeing the DML's run once per the entire test run which includes multiple test methods.

    • @cassioorsi
      @cassioorsi Před 7 měsíci

      TestSetup only runs once.
      Then the test methods run.

  • @richhuynh6314
    @richhuynh6314 Před 8 měsíci

    First I’m first