Apex tests are isolated from existing org data by default. Tests don't see records that exist in the org; they must create their own.
apex @isTest private class MyTest { @TestSetup static void setup() { Account a = new Account(Name='Test Co'); insert a; } @isTest static void testAccountUpdate() { Account a = [SELECT Id FROM Account LIMIT 1]; a.Phone = '555-0000'; update a; } }
@TestSetup runs once per class, rolls back at end — efficient for shared test data.
Test.isRunningTest() — at runtime, lets your code branch on test context.
@isTest(SeeAllData=true) — overrides isolation. Strongly discouraged. Tests should be deterministic; if they depend on prod data, they are flaky.
Test data factory pattern: a TestDataFactory class with createAccounts(n) etc., reusable across tests.
