Bulk API 2.0: BOM in CSV Files Causes Partial Failure Mapping Issues
0 reputation · 19 Jul 2020, 22:34 UTC
0 reputation · 19 Jul 2020, 22:34 UTC
When ingesting CSV data with Salesforce Bulk API 2.0, a file that begins with a UTF‑8 Byte Order Mark (BOM) can trigger partial failures. The API reports these failures, but the returned error log does not include the record number or line offset, making it difficult to pinpoint the problematic rows.
The objective is to measure the latency and ambiguity introduced by this behavior before applying any optimization. Constraints include the need to work with API version 58.0 or later, the lack of formal documentation on BOM handling in Bulk API 2.0, and the requirement to avoid impacting production data loads.
1. What API calls or log entries can be leveraged to correlate error rows with CSV lines when a BOM is present?
2. Is there a configuration setting or recommended pre‑processing step that ensures record numbers are preserved in the error log?
3. How does the current Bulk API 2.0 implementation treat BOM characters during parsing, and can this behavior be overridden or documented in a future release?
34775 reputation · 20 Jul 2020, 05:29 UTC
To resolve partial failure mapping issues and restore accurate line numbering in Bulk API 2.0 error logs, you must strip the Byte Order Mark (BOM) from the CSV file before uploading. Bulk API 2.0 does not provide a configuration setting to ignore the BOM; it treats the leading bytes as part of the first column header, which shifts the parser's alignment and obscures record correlation in the failed results log.
When a UTF-8 BOM (EF BB BF) is present, the API parser interprets these bytes as characters belonging to the first header field. This creates a mismatch between the expected header name and the actual bytes received. Consequently, the parser may fail to map the first column correctly or offset the line count. Because the error is rooted in the file's metadata rather than a specific data row, the failedResults log often fails to provide a reliable line offset, as the internal pointer for the first record is corrupted.
Since this behavior cannot be overridden via API settings, apply one of the following pre-processing commands based on your environment:
sed to remove the BOM from the first line:
sed -i '1s/^\xEF\xBB\xBF//' data_upload.csv[IO.File]::ReadAllText('data_upload.csv').TrimStart("\uFEFF") | Set-Content -Encoding UTF8 data_upload.csvTo measure the impact and verify the fix without affecting production data, use a sandbox environment with API version 58.0 or later:
GET /services/data/vXX.0/jobs/ingest/{jobId}/failedResults/. Note if the line number is missing or offset.failedResults log now correctly identifies row 3 as the failure point.To refine this recommendation, please specify the line ending format (CRLF vs LF) used in your source files, as multi-byte character handling can occasionally interact with line-break parsing to produce varying offsets.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.