Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Salesforce QA / Tester
easy

How do you test validation rules?

Validation rules must fire when expected and not fire when not.

Test cases:

  • Should fire: invalid record save attempt; expect error.
  • Should not fire: valid record save; expect success.
  • Edge cases: boundary values, null handling.

Apex test pattern:

@isTest
static void testRuleFiresOnInvalid() {
    Account a = new Account(Name=null); // missing required
    try {
        insert a;
        System.assert(false, 'Should have thrown');
    } catch (DmlException e) {
        System.assert(e.getMessage().contains('Required'));
    }
}

@isTest
static void testRuleAllowsValid() {
    Account a = new Account(Name='Valid');
    insert a;
    System.assertNotEquals(null, a.Id);
}

Manual / UI testing:

  • Try invalid input in UI.
  • Confirm error message shown.
  • Try valid input; confirm save.

Common pitfalls:

  • Only testing happy path.
  • Not testing the error message text.
  • Validation rules with complex logic insufficiently tested.

Senior insight: validation rules are easy to break. Tests catch regressions.

Why this answer works

Foundational. The Apex pattern is mature.

Follow-ups to expect

Related dictionary terms