SalesforceTrailhead
  • Today
© 2026 Salesforce, Inc. All rights reserved. Privacy Terms of Use Trust Accessibility Cookie Preferences
Apex Testing

Create Test Data for Apex Tests

+500 Points~45 minsHands-On Challenge
Apex TestingCreate Test Data for Apex Tests

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:

  • Create a test utility class.
  • Generate test data in tests.

Concepts

Tests can't see org data by default. A test data factory creates the records each test needs, so tests stay independent and repeatable.

Hands-On Challenge

  1. Create a public @isTest class RandomContactFactory.
  2. Add a static method generateRandomContacts(Integer count, String lastName) that returns contacts named Test 1, Test 2, and so on.
Check ChallengeDemo check
Previous UnitTest Apex TriggersBack to Badge Apex Testing