## TL;DR
InvalidBatch tells you the job container was fine and one batch inside it was not, so stop restarting the whole sync and go batch hunting. Open the Bulk API job, read the failed batchs own error, and you will usually find a malformed SOQL query, a CSV payload problem, or an unsupported operation in that batch alone. Fix that batch, resubmit only the failed portion, and the health fields land without a risky full reload.

```text
Salesforce Bulk API InvalidBatch failed to process query when syncing account health fields to the CRM
```

## Use this when
- A Salesforce Bulk API job completes with failed batches in InvalidBatch state
- Some account health fields updated and others are stale from the same run
- The same sync worked at smaller volume or with a narrower query

## Not for this skill when
- Every batch fails identically from the job creation step, which points at authentication or API version instead
- Single record updates through the UI also fail, suggesting validation rules rather than bulk formatting

## Steps
1. Retrieve the job and its batch list through the Bulk API or your integration tool, and capture the state message for each InvalidBatch batch rather than the jobs summary line. The batch-level message names the real problem, such as a malformed query, an invalid field, or a formatting error in the records payload. Verify: the failing batches and their individual messages are listed
2. If the failing batch is a query batch, take its SOQL into Salesforce Workbench or the query editor and run it there unchanged. Bulk query rejects some constructs that interactive SOQL tolerates, including certain aggregate and date literal patterns, and a field renamed in the org breaks every batch that selects it. Fix the query to the Bulk-supported shape and confirm it returns rows in the test. Verify: the corrected query executes in the test tool and returns the expected account set
3. If the failing batch is an update batch, inspect its payload file around the reported row. Common killers are unescaped commas and quotes in CSV, a health score sent as text with locale decimal separators, empty strings sent for numeric fields instead of null markers, and external id values containing characters that break the file structure. Regenerate the payload with a real CSV writer and explicit null handling. Verify: the regenerated payload passes a local parse and row count check matching the source extract
4. Check field level reality in the org. Confirm the health fields exist in this org, the integration profile can edit them, and no new validation rule or duplicate rule rejects the values the sync sends, for example a rule demanding a score reason whenever the score changes. Test one record update through the REST API with the same payload values to surface org-side rejections in plain language. Verify: a single record updates cleanly with the same values, or the org rule blocking it is named
5. Resubmit only the failed batches as a new job, keep the successful batches out of it, and reconcile by counting accounts whose health fields carry todays sync timestamp against the source extract count. Reconcile on counts and samples, not on job status alone. Verify: resubmitted batches complete and the reconciled account count matches the source
6. Harden the sync. Validate payloads against the org schema before submission, split batches by operation and segment so one bad shape cannot poison a whole run, and alert on any batch ending in a failed state with its message attached to the alert so the next occurrence arrives pre-diagnosed. Verify: the pre-flight validation and batch state alert are in place and tested with a deliberately bad batch

## Why it happens
A bulk job is a set of independent batches, and Salesforce marks a batch InvalidBatch when its own content cannot be processed, while sibling batches succeed. Integrations that only watch job status either miss the partial failure or retry the entire load, duplicating updates and still failing on the same bad batch. Partial staleness in the health fields is the visible symptom of that one poisoned batch being skipped run after run.

Compatibility: Salesforce Bulk API 1.0 and 2.0 job and batch model, Workbench query testing, and current Salesforce org validation and profile controls.

## Variants and edge cases
### Salesforce Bulk API InvalidBatch state message meaning
['The meaning-first phrasing. InvalidBatch is a batch-level verdict, so always drill to the batch state message before changing job level settings.']

### bulk query batch failed health sync Salesforce
['The query-batch variant. Reproduce the SOQL outside the integration first, it is the fastest way to separate query problems from payload problems.']

### bulk update CSV batch invalid account health fields
['The payload variant, usually escaping or type formatting. Diff a failing row against a succeeding row from the same file to spot the pattern quickly.']

Edge cases to work through before you close the incident:
- Bulk API 1.0 and 2.0 differ in how jobs, batches, and errors surface. Confirm which version your integration uses before following menu paths or endpoint shapes.
- Hard delete and some operations need special permissions and behave differently in batches. Keep operation types in separate jobs so their failures stay legible.
- External id fields with case-sensitive values can match a different record than intended. Sample-check updated records by account name, not only by counts.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_34lWpGqYaxlOXo9SNbsa7Q
