OrgReady

Salesforce Skills & Readiness

Learning progress is unavailable. Reading and direct practice remain available; completion controls are disabled.

← Back to Salesforce Development

Lesson 4 of 6 · 5–10 minutes including the walkthrough and reflection

Apex Testing

Tests should demonstrate behavior, not merely execute lines. Clear setup, action and assertions make failures useful during review.

The concept

Create test data for the behavior under test. Exercise both expected and unexpected inputs, then assert meaningful outcomes. Test.startTest and Test.stopTest delimit the tested operation and support testing asynchronous work. Coverage is useful information, but assertions establish what behavior the test actually checks.

Worked example

Illustrative test plan:
Arrange: create isolated input records
Act: invoke the operation under test
Assert: verify expected field values and side effects
Repeat: invalid input, no-op input and bulk input

For an imaginary normalization service, checking only that no exception occurred misses wrong output. An assertion about the normalized value tests the requirement. A second case with already-normalized input tests that unnecessary changes do not occur. Keep expected values independent of the implementation being tested.

Common mistake

Using an always-true assertion, or relying on unrelated existing organization records to make a test pass.

Interview angle

Explain what regression each test would catch and what remains untested. Distinguish coverage from confidence in requirements.

Pause and apply

Write a test matrix with three columns: input, expected result and observable assertion. Include a failure case and a collection. Identify one bug that your original happy-path test would miss. The linked practice is a broader AI-generated change review; focus on testing while recognizing that its complete answer also requires engineering and security review.

Official references

Reviewed 2026-09-13. Examples are illustrative; no code is executed here.

Apply it in practice

Review AI-Generated Apex, LWC, and Flow Changes

Marking a lesson as read records learning activity, not mastery. Practice evidence continues to come from the challenge system.