Montag, 4. April 2016

Problem with XML Input for Bulk API when Using Relationship Fields (INVALID_FIELD_FOR_INSERT_UPDATE)

Few days ago I discovered a strange bug in Salesforce, which costed at least half a day to resolve. The bug concerns the Bulk API and XML input. Suppose you have an input with references like this:

        <sObject>
            <LastName>a1-ContactWithRelationship</LastName>
            <Account>
                <sObject>
                    <account_external_id__c>ab123</account_external_id__c>
                </sObject>
            </Account>
        </sObject>


Here I was trying to update a Contact and set the account reference to a new value.
As a response I got the following error message from Salesforce:

<errors><fields>Account</fields><message>Contact: bad field names on insert/update call: Account</message><statusCode>INVALID_FIELD_FOR_INSERT_UPDATE</statusCode></errors>

The same request sent using REST API succeeded, so I had no evidence what I am doing wrong until I found this thread:

https://developer.salesforce.com/forums/?id=906F00000008kOpIAI

It turned out that this is a bug in SF Bulk API (known for at least 5 years!). To resolve this you have to remove all whitespaces and line breaks in your XML or at least in the sObjects section. So the problem was the pretty-print and that is kind of ridiculous nowadays!

Hope, this would be helpful.

Keine Kommentare:

Kommentar veröffentlichen