Try Serpent Free

How to fix FIELD_CUSTOM_VALIDATION_EXCEPTION in Salesforce deployments

A custom validation rule in the target org blocked the record, and the error text is the rule's own message.

Surfaces during: runtime DML, most often inside Apex test execution

What it means

FIELD_CUSTOM_VALIDATION_EXCEPTION means a validation rule you or another admin configured rejected the record being saved. Salesforce appends the validation rule's exact error message to the exception, so the fix is usually visible directly in the error text, once you know which record and which rule triggered it.

Because deployments to production run Apex tests against production's real, active validation rules, this is one of the most common ways a validation rule that was fine in a sandbox blocks a release: the sandbox simply didn't have that rule turned on.

Diagnosis

Common causes

Test data does not satisfy the rule
An Apex test's data factory builds records that violate a validation rule active in the target org but not in the source sandbox.
Validation rule inconsistent across environments
The rule's activation state or logic differs between environments because a change was not promoted everywhere.
New rule conflicts with existing data patterns
A validation rule added in the same deployment conflicts with how existing automation or tests build records.

The fix

  1. Read the rule's own error text
    The message after the error code names the exact condition that failed; start there instead of guessing.
  2. Update the test data factory
    Adjust the Apex test setup so generated records comply with the validation rule's condition.
  3. Align rule activation across orgs
    Confirm the validation rule is active (or inactive) consistently in every environment the deployment touches.
In practice

How Serpent prevents this

Serpent AI surfaces the exact validation rule message during preflight, before the real deployment runs, so you fix the rule or the data once instead of guessing. See the Salesforce deployment error library.

Metadata and data in one deployment flow in Serpent

Prevention

Deploy validation rules with the same rigor as Apex
Track validation rule changes in source control and promote them through the same pipeline as code, instead of editing them ad hoc in one org's Setup.
Build test data factories from the object's active rules, not tribal knowledge
Review every active validation rule on an object when writing its test data factory, rather than relying on what happened to pass in the past.
Validate against a production-like sandbox before release
Run a check-only deploy against a full sandbox with production's real validation rules active, so a rule gap surfaces before the release window, not during it.
Common questions

FIELD_CUSTOM_VALIDATION_EXCEPTION, answered

Is it safe to just deactivate the validation rule during deployment?
Only as a last resort, and never in production. Fixing the underlying test data or record is safer than turning off a rule that protects real data.
Can a validation rule fire on a field that isn't visible on the page layout?
Yes. Validation rules evaluate the record's saved field values regardless of page layout visibility, so a hidden field can still block a save.
Why does the same test pass when run alone but fail in the full suite?
Another test earlier in the run likely changed shared state, a custom setting, a record the validation rule checks, that the failing test's data now violates. Isolate the earlier test to confirm.

Start free. No credit card, no install, no commitment.

Set up in under 15 minutes. No DevOps hire needed.

Curious about faster shipping before you dive in? Let's talk

Commitment free!