TL;DR
FIELD_CUSTOM_VALIDATION_EXCEPTIONmeans custom validation rejected the record: a validation rule, or Apex callingaddError()in a trigger. It is not a platform limit and not a permissions problem.- The message carries everything you need to find the cause. The text after the comma is the rule's error message, and the brackets at the end name the field it is attached to, or are empty when the error shows at the top of the page.
- Validation rules run on every save, whatever the source: UI, Apex, REST, SOAP, Bulk API and Data Loader. They run after before-save flows and before triggers, so automation that fills in a field can satisfy a rule before it is evaluated.
- Most rules are written for a person editing one record. Integrations and loads trip them because they arrive with different fields, different order and no human to fix the screen.
- Where the rule is right, fix the data. Where the integration is a legitimate exception, use a custom permission in the rule. Deactivating rules during a load is the option most likely to go wrong.
What You'll Learn
- How to read the error and find the rule that raised it in under a minute
- Where validation sits in the order of execution, and why it matters for integrations
- The custom permission bypass, built step by step
- Why a new validation rule can break deployments of unrelated code
- How to handle rejected rows in Data Loader and the Bulk API
The Problem
It shows up in a few different wrappers depending on where the save came from:
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Close Date cannot be in the past: [CloseDate]
"errors": [{ "statusCode": "FIELD_CUSTOM_VALIDATION_EXCEPTION", "message": "Close Date cannot be in the past", "fields": ["CloseDate"] }]
Or as one line among thousands in a Data Loader error file. The records save fine from the UI. They fail from the integration, or from the overnight load, or in a test class that has worked for two years.
The cause is rarely mysterious. Somebody wrote a rule for people, and something other than a person is now saving records. The hard part is choosing the fix, because the quick one (switch the rule off) creates a bigger problem than the one it solves.
Common questions this article answers:
- How do I find which validation rule is blocking my integration?
- Can I let my integration user skip a validation rule without deactivating it?
- Why did adding a validation rule break a deployment that has nothing to do with it?
Quick Answer
FIELD_CUSTOM_VALIDATION_EXCEPTION is returned when a validation rule evaluates to true for the record being saved, or when Apex calls addError() on it. The message after the comma is the error text configured on the rule, so search for that text in Setup under the object's Validation Rules, and the bracketed field shows where the error is attached. Validation rules run on saves from every source, including the API and Data Loader, after before-save flows and before triggers have run. When the rule reflects a real business requirement, fix the data at the source. When a specific integration or load is a legitimate exception, create a custom permission, assign it to the integration user through a permission set, and add NOT($Permission.Bypass_Validation) to the rule's formula. Avoid deactivating rules for a load: it leaves the org unprotected for every other user during the window and is easily left switched off.
Find the rule
The error message is the rule's own error text, word for word. In Setup, open the object, go to Validation Rules, and match the message. In an org with dozens of rules per object, a quicker route is a Tooling API query:
sf data query --use-tooling-api --target-org prod \
--query "SELECT ValidationName, Active, ErrorMessage, ErrorDisplayField FROM ValidationRule WHERE EntityDefinition.QualifiedApiName = 'Opportunity'"
Scan the ErrorMessage column for the text in your error. ErrorDisplayField matches the bracketed field name, or is blank for rules that show at the top of the page.
If no rule matches, the error came from Apex. Search the triggers on that object for addError( with the same message. Trigger errors added with addError() are reported with the same status code, which surprises people who expect a different one for code.
Where validation runs
Two facts from the order of execution decide most integration cases.
Validation runs for every save, from every source. The UI, Apex DML, REST and SOAP API calls, the Bulk API and Data Loader all reach the same step. There is no setting to exempt an API call as such. What differs is the running user, and the bypass below relies on that.
It runs after before-save automation. The sequence on save is: before-save record-triggered flows, then before triggers, then system validation again plus custom validation rules, then duplicate rules, then the save. So a before-save flow or before trigger that fills in a derived field runs first, and a rule that checks that field sees the filled-in value.
That second point gives you a fix option that is often overlooked. If an integration fails because it does not send a field that can be derived (a region from a postcode, a default stage, a currency from the account), set it in a before-save flow when it is blank. The rule stays fully active and the integration's payload does not change.
One more detail. Workflow field updates do not re-run custom validation rules. Older orgs sometimes have records that are invalid by their own rules for this reason, and an integration that updates one of those records, even to change a single unrelated field, will hit the rule on the record's existing values.
Once you know which rule fired, the picker below helps choose between fixing the data, deriving the field, granting a bypass and fixing test data. The sections that follow explain each option.
Where did the failing save come from?
Fix the data before the rule
Find the rule from the message text first, then decide whether the rule or the save is wrong.
Why rules built for people block integrations
Read the failing rule and it is usually one of these shapes:
| Rule shape | Why it fails from an integration |
|---|---|
| "Field X is required when Stage is Y" | The integration sends Stage in one call and X in a second, or not at all |
ISCHANGED or PRIORVALUE comparisons |
An upsert that re-sends every field looks like a change to fields that did not change |
| Date rules such as "Close Date cannot be in the past" | A historical load is full of past dates, by definition |
Rules that check $User.ProfileId or a username |
Written for one user, and break when the integration user or profile changes |
| Picklist sequence rules ("cannot move from Closed back to Open") | A sync that replays state from another system can arrive in a different order |
The first two are usually fixable at the integration: send the fields together, and send only fields that changed. The date and sequence rules are where a legitimate exception exists. A historical migration genuinely needs to create closed opportunities with past close dates.
Bypass with a custom permission
The pattern that has replaced hard-coded profile ids is a custom permission referenced in the rule. It ties the exception to something you grant explicitly, it travels through deployments as metadata, and it shows up in access reviews.
- Create the custom permission. Setup, Custom Permissions, New. Name it something specific, such as
Bypass_Opportunity_Validation, and describe who is meant to hold it. - Put it in a permission set. Create a permission set such as
Integration Validation Bypass, add the custom permission, and assign the set to the integration user only. - Add it to the rule. Wrap the existing formula:
AND(
NOT($Permission.Bypass_Opportunity_Validation),
CloseDate < TODAY(),
ISNEW()
)
The rule now evaluates as before for every user except holders of the permission.
Three cautions keep the bypass honest. Scope it per object or per rule group so the integration skips only the checks it has a reason to skip. Keep the holders to integration and migration users, and do not hand it to admins for convenience. And review it alongside other elevated access, because a bypass permission on a human account is a quiet way around controls that exist for audit reasons.
For a one-off migration, assign the permission set for the load and remove it afterwards. Removing a permission set assignment is one action and leaves the rule itself untouched.
Why deactivating the rule is the worst option
It looks simplest: switch the rule off, run the load, switch it back on. Three things go wrong:
- It is org-wide. Every user who saves a record during the window skips the rule too, and nothing marks the records they saved.
- It drifts. The rule is inactive in production and active in source control. The next deployment either re-activates it unexpectedly or, if someone retrieves first, commits it as inactive.
- It is forgotten. Loads overrun, people go home, and the rule stays off until someone notices invalid data weeks later.
The custom permission takes about ten minutes longer to set up the first time, and every later load reuses it.
The deployment that broke for no reason
A classic report: an admin adds a validation rule to Opportunity, and the next deployment of unrelated Apex fails in a test class nobody has touched.
The test class creates opportunities to test something else, and its test data does not satisfy the new rule. Validation rules run in tests like everywhere else, so the test's own setup fails with FIELD_CUSTOM_VALIDATION_EXCEPTION, and because deployments to production run tests, the deployment fails.
Two habits prevent it. Build test data through a shared factory so a new rule means one change instead of forty, and run all local tests against a sandbox when a validation rule is added, the same way you would for a code change. The bypass permission is not a fix here, since test data should satisfy the org's rules.
Data Loader and Bulk API: handle the rejects
In Data Loader and the Bulk API, each record succeeds or fails on its own, so a rule violation fails that row while the rest of the batch saves. Data Loader writes failures to its error file with the full message per row. That file is the working list: fix the rows at source, then load only the error file again.
Apex DML is different. A plain insert records; is all or nothing, so one rejected record rolls back the entire list. Use Database.insert(records, false) and read each SaveResult. The status code on each error is available as StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION, which lets integration code route validation failures to a review queue and retry other failures differently.
Frequently Asked Questions
Q: Does Data Loader skip validation rules?
A: No. Data Loader saves through the API, and validation rules run on API saves. The common bypass is a custom permission on the user running the load.
Q: Why does the error have empty brackets at the end?
A: The rule's error location is set to the top of the page, not to a field. The message text is still the rule's own error message, so search on that.
Q: Can a flow throw this error?
A: Yes, indirectly. If a flow creates or updates a record and that save fails a validation rule, the flow fault carries the same status code. The rule to look at is on the object the flow was writing to, which is not always the object that started the flow.
Q: Should I use a hierarchy custom setting instead of a custom permission?
A: Both work in a formula. A custom permission is assigned through permission sets, so it appears in the same access reviews as every other permission, and is the easier one to audit. Hierarchy custom settings are useful when Apex also needs to check the bypass cheaply, but they are one more place to look when asking who can skip a rule.
Q: Do validation rules run on lead conversion?
A: Only if Lead Settings has "Require Validation for Converted Leads" enabled. When it is, conversion can fail with this error on the account, contact or opportunity being created.
Key Takeaways
- The error is a validation rule or an
addError()call. The message and the bracketed field identify which one. - Validation runs on saves from every source, after before-save flows and before triggers.
- Derive missing fields in a before-save flow when the integration cannot send them, and the rule stays fully active.
- Use a custom permission for legitimate exceptions, granted through a permission set to integration and migration users only.
- Do not deactivate rules for a load. The exposure is org-wide and the rule drifts from source control.
- New rules break old tests. Build test data through a shared factory and run tests when a rule is added.
What's Next?
Recommended Reading:
- INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY: what it means and how to fix it
- Apex test data frameworks and CI tooling
- Salesforce org-to-org migrations
Action Items:
- Run the Tooling API query above for the objects your integrations write to, and list the rules that compare against
$Useror$Profile. - Replace any hard-coded profile or user checks with a custom permission granted through a permission set.
- Check whether any rule is currently inactive in production but active in source control.
Responses
Checking your session.
Loading responses.