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
BrockBBrockB 

Bulk API Relationship Fields with CSV

Hi

I am trying to upsert contacts and accounts via the bulk API and all is working fine except the contact and accounts are not being connected to each other.

I am using a csv spec as described in the documentation to map my columns.
I have a custom external ID called 'User ID' (API name: 'User_ID__c') on my contact object AND on my account object.
I already have an Account record setup with a User id set as 5.
I also have a custom field called 'Display Name' on my contact object.

This is basically the batch CSV file I upsert to the Contact object.

"User ID","Display Name","Account Relationship",
"5","Mr Test","5",


Here is the spec CSV file I upload before the batch:

Salesforce Field,Csv Header,Value,Hint
User_ID__c,"User ID",,
Display_Name__c,"Display Name",,
Account__r.User_ID__c, "Account Relationship",,


The batch is upserted fine and processed without any errors. But the account and contact is not connected. When I monitor the job batch by logging in to the website, and downlaod the request, it does not have the relationship field in it:

"Display_Name__c","User_ID__c","Mr Test","5",



Do relationship fields work with CSV files? I can see there are issues with the XML version via another post

Please help
Best Answer chosen by BrockB
BrockBBrockB
Ok so I tried pulling out all of the account Ids from existing accounts, and then upserting the contacts with an 'AccountId' column. That didn't work either!

So... it turns out that its the spec that creates the problem! I cannot have a relationship field in my upsert when using a spec.

If I upsert the contacts with an 'AccountId' column, with no spec, it creates the relationship properly.

Or if I upsert the contacts with a 'Account.User_ID__C' column, it creates the relationship as well. This was saves me querying all of the accounts I upload and mapping them manually.

Thanks Salesforce. You owe me a day of my life back.

I hope this saves someone else some hassle.

All Answers

vsabbellavsabbella
accountId field on contact record should be mapped to Id of account that contact belongs to.
BrockBBrockB
That will involve me pulling back the upserted accounts to then find the account id that was assigned to the record automatically. Accoring to the documentation, I should be about to map to an indexed field name (in this case the User ID) on the account.

Relationship Fields in a Header Row

Many objects in Salesforce are related to other objects. For example, Account is a parent of Contact. You can add a reference to a related object in a CSV file by representing the relationship in a column header. When you're processing records in the Bulk API, you use RelationshipName.IndexedFieldName syntax in a CSV column header to describe the relationship between an object and its parent, where RelationshipName is the relationship name of the field and IndexedFieldName is the indexed field name that uniquely identifies the parent record.

BrockBBrockB
https://www.salesforce.com/us/developer/docs/api_asynch/Content/datafiles_csv_rel_field_header_row.htm
BrockBBrockB
I am using APi version 30.0. Tried to use 31.0 but it just says invalid URL or unsupported API version .. but thats a different issue
vsabbellavsabbella
Import all the account Ids and User_ID__c from account object into csv file.
.Then try using the excel feature vlookup to match accountIds related to your external Id field User_ID__c and then provide those accountIds as reference in your contact csv
BrockBBrockB
I am upserting the accounts too, before the contacts. I am tring to integreate with the API to create an automatic push each day. So using excel just defeats the purpose. Thanks for your help tho
BrockBBrockB
Ok so I tried pulling out all of the account Ids from existing accounts, and then upserting the contacts with an 'AccountId' column. That didn't work either!

So... it turns out that its the spec that creates the problem! I cannot have a relationship field in my upsert when using a spec.

If I upsert the contacts with an 'AccountId' column, with no spec, it creates the relationship properly.

Or if I upsert the contacts with a 'Account.User_ID__C' column, it creates the relationship as well. This was saves me querying all of the accounts I upload and mapping them manually.

Thanks Salesforce. You owe me a day of my life back.

I hope this saves someone else some hassle.
This was selected as the best answer
S i dS i d

Hi BrockB

I'm facing the same issue today.

  • I have an external ID on the USER called "REP_ID__C"
  • I want to update the ParentId, and OwnerId on an Account via Bulk API 
  • My CSV headers and values should be  ??