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
Bruce GreerBruce Greer 

Failure using bulkapi/CSV to create Contact with non-default OwnerId

I have working code that I use to create batches of new Contacts using input data in a CSV-formatted file.  The Contact column names are in the first row of the file, followed by one or more rows containing the values for each Contact that I need to create.  The working version of the code does not specify the OwnerId of the new Contact, so each Contact created is assigned to the default Owner value, which is the admin user that created the API session.

I need to modify the logic to assign a different Owner to the new Contacts that are created.  I found this section in the documentation, where it specifically refers to the "Owner" relationship.  I added "Owner.Id" as a new name to the first row of the CSV file, but when I attempt to create a new Contact, the upload fails with the message "InvalidBatch : Unable to find relationship:  Owner".  "Owner" is the name of the relationship that I can use successfully in the query, why doesn't it work in the batch create?

Does anyone have an idea about what I could be doing wrong?

Thanks for you time!
Best Answer chosen by Bruce Greer
Bruce GreerBruce Greer

Turns out, the primary problem with my implementation is that it was putting a space before the name of the Owner field in the first row of the CSV file.  So it didn't matter if I used " OwnerId", or " Owner.Id" or " Owner.Username", they all generated errors of "unable to find relationship" or "Field name not found".

Since I changed the logic that generates the first row of the CSV file to contain the field names without spaces, things are functioning much more predictably now.

Bottom line:  Don't put spaces in the first line of your CSV input file.

All Answers

EmilienGuichardEmilienGuichard
Hello,

If you want to assign records to a diffrent owner than the running user you need to specify a new column in your file.

Call it "OwnerId" so it will be mapped automatically when you click on automatch button when you specify the mapping.

Owner Ids are a user Id in Salesforce (beginning with 005).

Hope it helps.
Bruce GreerBruce Greer

Turns out, the primary problem with my implementation is that it was putting a space before the name of the Owner field in the first row of the CSV file.  So it didn't matter if I used " OwnerId", or " Owner.Id" or " Owner.Username", they all generated errors of "unable to find relationship" or "Field name not found".

Since I changed the logic that generates the first row of the CSV file to contain the field names without spaces, things are functioning much more predictably now.

Bottom line:  Don't put spaces in the first line of your CSV input file.

This was selected as the best answer