function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
po3211po3211 

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?

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
po3211po3211

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

po3211po3211

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?

po3211po3211

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.

This was selected as the best answer
Mark SFMark SF

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.

 

 

po3211po3211

That's just a typo when I was putting this post together. Thanks for trying though.

dkadordkador

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.

nicInfnicInf

Hi

 

Am encountering the same problem - did anyone ever find the solution?

Andy CrossmanAndy Crossman

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?? ;-)

dkadordkador

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:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload"><sObject><FirstName>Test</FirstName><LastName>RelField</LastName><ReportsTo><sObject><Email>barr_tim@grandhotels.com</Email></sObject></ReportsTo></sObject></sObjects>

 There are no newlines anywhere here except for after the XML preamble.  Sorry for the inconvenience, folks.

 

nicInfnicInf

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

 

 

satchsatch

This still appears to be a bug. It caused me a lot of grief recently. Any progress on a fix?

Bruno GBruno G
This is still the case with API 29: you still need to strip white spaces !

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...
Amlan SenguptaAmlan Sengupta
After completely wasting a day by trying to perform upserts using XML BULK API calls, this idea helped me out to resolve the issue.

Someone please update the documentation if not able to fix the issue !!
Jan StaufenbergJan Staufenberg
Thank you very much @dkador! We've had a lot of trouble until we found this issue. It would be great if this would be fixed, since it's already 4 years ago...
Benjamin VellacottBenjamin Vellacott
This still doesn't seem to be fixed!?
Benjamin VellacottBenjamin Vellacott
Confirmed - still doesn't work
Pham HanhPham Hanh
One year later. It is still not fixed, but the workaround to have no indentation works. Please update the documentation, if you do not fix the problem. I finally found this thread, but it has cost me quite some hours...