You need to sign in to do that
Don't have an account?
Bulk API Relationship Fields
I'm following the documentation on updating an object with a relationship field, but I'm getting an error. The documentation says to format the xml as such when referring to a relationship field:
<RelationshipName> <sObject> <IndexedFieldName>rwilliams@salesforcesample.com</IndexedFieldName> </sObject> </RelationshipName>
In my case the xml looks something like this:
<?xml version=\"1.0\" encoding=\"UTF-8\"?> <sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <sObject> <location_external_id__c>1234</location_external_id__c> <Name>My Location</Name> <Account__r> <sObject> <account_external_id__c>7890</account_external_id__c> <sObject> </Account__r> </sObject> </sObjects>
This is an attempt to upsert to a custom object (Location__c) with an external id api name of 'location_external_id__c' that has a text field called 'name' and a Master-Detail(Account) field with relationship name 'Account__r'. Account has an external id field called account_external_id. As far as I can tell this is all following the documentation for the bulk api. However I get back an error like this:
<results xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <result> <errors> <fields>Account__r</fields> <fields>sObject</fields> <fields>account_external_id__c</fields> <message>Location__c: bad field names on insert/update call: Account_r, sObject, account_external_id__c</message> <statusCode>INVALID_FIELD_FOR_INSERT_UPDATE</statusCode> </errors> <success>false</success> <created>true</created> </result> </results>
This looks to me like the Bulk API doesn't know anything about relationship fields despite what the documentation clearly says. Hopefully I'm just doing something wrong, does anyone have any ideas?
Warning to others: The Bulk API does not support relationship fields with XML making it pretty much useless. The documentation says otherwise, but it's wrong. Don't bother calling support about it, they won't know what you're talking about if they even try to help.
All Answers
I can't be the only person using the bulk API with XML can I? I can't find anything out there on this except in the docs, which appear to be wrong. Anyone?
Warning to others: The Bulk API does not support relationship fields with XML making it pretty much useless. The documentation says otherwise, but it's wrong. Don't bother calling support about it, they won't know what you're talking about if they even try to help.
The XML in your example does not look well formed to me. Try again with a closing </sObject> tag inside the relationship field.
<Account__r>
<sObject>
<account_external_id__c>7890</account_external_id__c>
</sObject>
</Account__r>
I hope that helps.
That's just a typo when I was putting this post together. Thanks for trying though.
Try removing the nested <sObject> tags. I'm pretty sure they're not necessary.
I'll work with our doc team to fix the documentation up. Thanks for finding the problem.
Hi
Am encountering the same problem - did anyone ever find the solution?
Hi - is there any update on when this might get fixed?
Could the API help be amended to say this doesn't work yet, rather than everyone have to spend hours scratching their heads and then find the answer in the forum?? ;-)
I've looked into this more and determined it's a bug on our end. We'll get this fixed soon. In the mean time, you can workaround this by not pretty-printing your XML. Meaning don't include any whitespace between your element tags. So the following will work:
There are no newlines anywhere here except for after the XML preamble. Sorry for the inconvenience, folks.
Hi - many thanks - that does now work - just needed to strip out any white space incl carriage returns between ><
can all be on one line (ie no need to separate off the <xml..> preamble bit as you suggested)
Thanks again for advice
This still appears to be a bug. It caused me a lot of grief recently. Any progress on a fix?
I have lost a day on this before finding this post.
Come on, fix it or at least the documentation !
It is not like XML is a new technology...
Someone please update the documentation if not able to fix the issue !!