Skip to main content

Unit Testing

Explore practical guides and implementation patterns for this topic.

Posts

Salesforce Basics

🚀 Mastering Salesforce Mocking: HttpCalloutMock & StubProvider Explained

💬 In plain words: Apex tests cannot make real callouts to external systems. Instead of hitting a live endpoint, you hand your test a "fake phone." Using HttpCalloutMock , you return a scripted response that you control. You use the exact same strategy for internal code dependencies using StubProvider . You are testing your own logic, not the uptime of an external system.
Read article
Apex Development

Dependency Injection in Salesforce Apex: Testability & Trade-offs

💬 In plain words: Dependency Injection (DI) simply means a class receives its tools from the outside instead of building them internally. By passing dependencies (like database selectors or API callout classes) into a class, you can easily substitute them with FAKE tools (mocks) during unit tests. This lets you test your core business logic instantly without making real database queries or external network callouts.
Read article
Apex Development

Apex Test Class Examples for @HttpPost Exposed WebService Class

💬 In plain words: Unit testing an Apex REST service marked with @HttpPost requires manually setting up RestContext.request and RestContext.response , populating URI parameters or request payloads, and executing positive and negative assertion tests against database state. In Salesforce, the Apex programming language allows you to create powerful web services exposed to external systems for seamless data integration. A common scenario involves using the @HttpPost annotation within a @RestResource class to accept incoming REST requests. In this post, we'll walk through writing effective test classes for an @HttpPost Apex REST web service, setting up RestContext , and handling positive and negative scenarios to achieve robust code coverage.
Read article
Topic Apex Assert Class Apex Debugging Checkpoints Developer Console Salesforce Apex Salesforce Development Unit Testing
Apex Assert Class Apex Debugging Checkpoints Developer Console Salesforce Apex Salesforce Development Unit Testing

Salesforce Checkpoints & Assertions: Complete Debugging & Testing Guide

In plain words: Checkpoints capture a complete snapshot of in-memory heap data and SOQL queries at a specific line of code without cluttering your logic with debug statements. Assertions are automated sanity checks that verify whether your code's real behavior matches your expected outcome. Diagnosing tricky edge cases and preventing regressions requires more than adding temporary System.debug() lines. Salesforce arms developers with two essential diagnostic tools: Checkpoints (detailed heap inspection during execution) and the modern Assert class (programmatic condition validation in unit tests and business logic). Mastering both helps you validate architectural assumptions and debug complex codebases faster.
Read article
Topic Architecture & DevOps
Salesforce Architecture & DevOps

How to Avoid Errors in Salesforce: 6 Essential Best Practices for Developers & Admins

In plain words: Avoiding errors in Salesforce comes down to writing bulkified code that respects Governor Limits, testing with realistic data volumes, logging failures systematically, and enforcing strict data security rules across your org. Salesforce is a multi-tenant cloud platform, meaning every transaction shares memory, CPU time, and database resources with other processes. When custom automation, Apex triggers, or integrations aren't built defensively, teams run into unhandled exceptions, locking issues, and broken user workflows. Following disciplined architecture principles keeps your org healthy and error-free.
Read article