I have a custom object (CustomObject__c) which is a child of another custom object. I want to import some records (CSV files) of CustomObject__c via SFDX (force:data:bulk:upsert
).
These are the custom fields of the CustomObject__c
- Name (Text (80))
- Parent_Object__c (Master-Detail)
- Locale__c (Lookup)
The problem is, CustomObject__c does not have any external ID (I cannot assign any relationship field to become the external ID) and sfdx force:data:bulk:upsert
needs an external ID.
I know there are Data Loader and Data Import, but I want to create a script and automate the process of creating a new scratch org later. I also know that there is force:data:tree:import
but it requires JSON format and what we have right now is CSV.
Is there any workaround for this?
EDIT:
I have imported the parent object records before executing this command.
Command:
sfdx force:data:bulk:upsert -s CustomObject__c -f csv/CustomObject.csv -i Id
CustomObject.csv:
Parent_Object__c,Name,Locale__c
tv,TV,de_DE
tv,TV,en_US
phone,Phone,en_US
phone,Handy,de_DE
car,Car,en_US
car,Auto,de_DE
Result:
=== Batch Status
jobId: 7501X000001ABCDE
state: Completed
createdDate: 2019-08-06T13:29:37.000Z
systemModstamp: 2019-08-06T13:29:46.000Z
numberRecordsProcessed: 6
numberRecordsFailed: 6
totalProcessingTime: 91
apiActiveProcessingTime: 2
apexProcessingTime: 0
Error:
=== Upsert errors
MALFORMED_ID:Parent Object: id value of incorrect type: tv:Parent_Object__c --
MALFORMED_ID:Parent Object: id value of incorrect type: tv:Parent_Object__c --
MALFORMED_ID:Parent Object: id value of incorrect type: phone:Parent_Object__c --
MALFORMED_ID:Parent Object: id value of incorrect type: phone:Parent_Object__c --
MALFORMED_ID:Parent Object: id value of incorrect type: car:Parent_Object__c --
MALFORMED_ID:Parent Object: id value of incorrect type: car:Parent_Object__c --
EDIT 2:
CustomObject_rev1.csv
Child_relationship_Name__r.Code__c,Name,Locale__c
tv,TV,de_DE
tv,TV,en_US
phone,Phone,en_US
phone,Handy,de_DE
car,Car,en_US
car,Auto,de_DE
I got an Error:
ERROR running force:data:bulk:upsert: InvalidBatch : Unable to find relationship: Child_relationship_Name__r
$ sfdx force:data:bulk:upsert -s MyObject__c -f ./path/to/file.csv -i Id -w 2
developer.salesforce.com/docs/…