Salesforce Apex: Running Unit Tests & Code Coverage Essentials - Part 2

Опубликовано: 08 Июль 2026
на канале: Code With Sally
1,427
24

Welcome back to the Apex Beginners' Guide with Sally! 🌟

In this session, we continue exploring Unit Testing in Salesforce Apex, focusing on how to run unit tests and understanding code coverage. This is Part 2, where we take a deeper dive into essential tools and concepts for writing reliable test classes.

🌟 What You'll Learn:
How to run unit tests using Developer Console, Salesforce UI, VS Code, and SF CLI Commands.
The importance of Code Coverage, why it works hand-in-hand with assertions, and how to avoid common pitfalls.
A quick recap on preparing data for testing and a live example of creating test data directly in the test method for a Contact Trigger.
Why relying on org data is discouraged and how to progress toward using testSetup and test data factories.

📌 Timestamps:

00:00 – Session Introduction: Overview of what will be covered in this session.
01:15 – Recap of Part 1: A quick review of the basics of unit testing and assertions.
02:19 – How to Run Unit Tests in Salesforce: Introduction to the importance of running unit tests.
04:40 – Running Unit Tests from Developer Console: Step-by-step demonstration.
06:28 – Running Unit Tests from Salesforce UI: How to execute test classes from the Setup menu.
07:35 – Running Unit Tests from VS Code: Demonstration of using VS Code for test execution.
09:20 – Debugging Test Methods in VS Code: How to debug test methods for better insights.
16:18 – Alternative Ways to Run Tests in VS Code: Using different VS Code commands for running tests.
17:40 – Running Unit Tests Using SF CLI Commands: Quick overview of command-line options.
19:40 – What is Code Coverage and Why is it Important?: Explanation of code coverage and how it complements assertions.
26:36 – Checking Code Coverage in Developer Console: Learn how to see code coverage reports.
29:52 – Checking Code Coverage in VS Code: Explore code coverage using VS Code tools.
32:22 – Live Example: Why Code Coverage Without Assertions is Risky: Demonstration of potential issues when assertions are missing.
36:41 – Data Preparation for Testing (Recap): Quick overview of three data preparation methods.
39:47 – Writing a Test Class for a Contact Trigger: Live example of creating data directly in the test method and why this approach is limited.
50:53 – Sneak Peek on What's Next: Preview of upcoming topics (testSetup, test data factories, bulk testing) and homework for attendees.

💬 Have Questions?
Drop your thoughts or coding challenges in the comments below!

🔔 Subscribe and hit the bell icon to stay updated with new videos.

🔗 Helpful Links:
Previous Video: Introduction to Apex Unit Tests - Part 1: Test Classes & Assertion [   • Introduction to Apex Unit Tests - Part 1: ...  ]
Code With Sally Blog: [https://codewithsally.com/]
LinkedIn: [  / sallyelghoul  ]

#salesforceapex #ApexUnitTests #CodeWithSally #UnitTesting #CodeCoverage #SalesforceDevelopment #Trailblazers #ContactTrigger #learnapex
=======================================
Music: https://www.bensound.com/free-music-f...
License code: JVCCZMX07AVZTG83

Music I use: https://www.bensound.com
License code: 7FC6QAPSOZAWJLOC