1

I am facing a bit problem while uploading csv data in salesforce org by data loader from command line.

I have master detail objects

OBJECT 1: Customer__c
 - Age__c
 - CustomerExternal_ID__c

OBJECT 2:  Customer_detail__c 
 - Customer_D__c
 - phone__c

I have two csv files for respective object. In the child (customer detail) csv file there will be some records having a common number which is unique in the master (customer) records.

I have created a external id field on the master object to store this unique number.

since I'll be running this through the command line and there will be no human intervention, I won't be able to add the recently added master record id in the child csv file.

i want that while inserting data in the child object, if system can take the external id mentioned in the child csv file and look in the master object with same external id and assign the id of matching master record to the Customer_D__c id in child object.

I have got one post having similar issue Parent Id Apex Data Loader

I tried doing below mapping in the .sdl(mapping file)

phone__c=phone__c
ExternalID=Customer__c\:CustomerExternal_ID__c

but this didn't work for me.

please help me out in this.

2 Answers 2

1

Assuming you are getting the following error:

Field mapping is invalid: ExternalID => Customer__c:CustomerExternal_ID__c

The problem is that you need to use the __r suffix when referencing the parent external id field in your mapping file:

phone__c=phone__c
ExternalID=Customer__r\:CustomerExternal_ID__c
2
  • Hi martin. i tired this and it still gave me invalid field mapping. i got this working in other way. i wrote a trigger before insertion of child object and updated the master id in the child object and got the child records inserted. Commented Apr 6, 2017 at 13:33
  • for those wondering, manually editing the sdl file using a text editor is your best bet with the above syntax
    – Jay Rizzi
    Commented Oct 20, 2022 at 16:54
0

posting my solution for this issue. if anyone is searching for a solution:

I wrote the below trigger before insertion of child object and updated the master id in the child object and got the child records inserted.

trigger UpdateCustomerDetailsWithID on Customer_detail__c (before insert) {

    Set<String> externalId = new Set<String>();

    for(Customer_detail__c cd: trigger.new){
        externalId.add(cd.ExternalID__c);
    }

    List<Customer__c> customers = [SELECT id, CustomerExternal_ID__c FROM Customer__c where CustomerExternal_ID__c IN: externalId];

    Map<String,ID> mapExternalIdAndCustomerId = new Map<String,ID>();

    for(Customer__c c: customers){
        for(Customer_detail__c cd: trigger.new){
            if(c.CustomerExternal_ID__c == cd.ExternalID__c){
                if(mapExternalIdAndCustomerId.get(c.CustomerExternal_ID__c) == null){
                    mapExternalIdAndCustomerId.put(c.CustomerExternal_ID__c, c.Id);
                }
             }
        }
    }


    for(Customer_detail__c cd: trigger.new){
        cd.Customer_D__c = mapExternalIdAndCustomerId.get(cd.ExternalID__c);
    }
      }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .