Issue
When syncing data to Salesforce (Actions) using Segment, the Custom Object V2 mapping works in the Mapping Tester but fails during regular production syncs.
The error InvalidBatch: Field name not found appears when attempting to use a non-External ID field for relationship lookup (xxx__r.xxx__c) in the Bulk Data Load Jobs.
For example:
Product
Twilio Segment
Environment
Segment Console
Cause
This issue happens because Segment uses two different APIs to send data to Salesforce during testing versus regular production syncs.
When you test using the Mapping Tester, Segment sends data using Salesforce's streaming REST API, which easily handles relationship lookups against non-text fields.
However, for regular production syncs, Segment uses Salesforce's high-volume Bulk API 2.0 to ensure efficiency. This bulk method has a much stricter rule: any field used to look up a relationship (xxx__r.xxx__c) must be a standard Text field marked as an External ID.
If you are using a field that is not marked as an External ID, the production sync will fail to recognize it.
Resolution
To fix this, you must store the ID in a standard Text field that is marked as an External ID in Salesforce. Follow these steps:
Log into your Salesforce account and navigate to the Object Manager.
Select the target object and create a new custom field with the data type Text.
In the field settings, check the boxes to mark this field as an External ID and Unique.
Save the field and ensure your system populates this new
Textfield with your unique IDs moving forward.Log into the Segment workspace, navigate to your Salesforce destination mappings, and update the mapping to point to your newly created
Textfield.
Additional Information
You can find more details here:
- Salesforce Docs: This explains that for Bulk API, the field in the related object must be an External ID.
Salesforce forum: Note that formula fields cannot be marked as External IDs, which is the requirement for Bulk relationship lookups.