Getting Started

  • What is Trailhead
  • myTrailhead
  • Trailblazer Community
  • Career Growth

Learn

  • Trails
  • Trailmixes
  • Modules
  • Projects

Credentials

  • Superbadges
  • Certifications
  • Maintain Certifications

Salesforce

  • Salesforce.com
  • AppExchange
  • Developers
  • Help Portal
© 2026 Salesforce, Inc. All rights reserved. Privacy Terms of Use Trust Accessibility Cookie Preferences
SalesforceTrailhead
  • Today
Advanced Apex Testing

Mock and Stub Objects

+1,000 Points~1 hrHands-On Challenge
Advanced Apex TestingMock and Stub Objects

Org:Mindful Goat Playground

Topics

  • Concepts
  • Hands-On Challenge

Looking for help?

Explore Help ResourcesShare Your Feedback
Learning Objectives

After completing this unit, you'll be able to:

  • Use the Stub API to mock dependencies.
  • Inject a mock into the code under test.

Concepts

The Apex Stub API (System.StubProvider and Test.createStub) replaces a dependency with a mock, so you can test a class without touching the database or a callout.

Hands-On Challenge

  1. Create a StubProvider implementation that returns a fixed account list.
  2. Inject it into AccountService and assert the service handles the list.
Check ChallengeDemo check
Previous unitGet Started with Advanced Apex TestingNext unit Test Security and Async Code