+ Start a Discussion
TarentTarent 

Data loader with lookup relationship

I want to know how to use apex data loader to insert data for the objects which have lookup relationship with other objects.I mean what data I put for these fields in csv file.

Navatar_DbSupNavatar_DbSup

Hi,

 

For creating the relationship via lookup field when inserting the data from data loader. Put a column of name as api name of lookup field in your csv file and put the ids of lookup object from which you want to associate the Childs records.

 

For example:

 

Suppose you want to associate a contact con1 with account acc1 then create a column as accountid and put the id of acc1 in this column and associate the contact con1.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

tggagnetggagne
Did you get the answer you were looking for?

I do a lot of work with dataloader at the command line, and it is possible to import data and have the relationships connect.  If you're interested, let me know and I'll post more specifics.
jjLAjjLA
tggane, i'm interested if you can relate a lookup between two custom objects using dataloader and command line. Please post more specifics if you can...
tggagnetggagne

Here's an under-used capability of dataloader.

Let's say we're importing purchase orders and purchase order lines from a foreign system (like a DB) into Salesforce.  The PO lines should include the PO number so the lines can relate to the POs.  In Salesforce, the PO object will (or should) include an "external id" field which is the same PO number as the lines will have.

Your mapping file (often with an .sdl extension) could have a line like:
 

po_number=Purchase_Order__r\:PO_Number__c

What that says is take the po_number field on the incoming PO lines and relate the new line in Salesforce with its parent Purchase_Order__c object, using the relationship Purchase_Order__r's external id field PO_Number__c.

Another example is loading Accounts from an external system where those accounts have a relationship to each other and that relationship should be preserved in Salesforce via an account's parent field.

If you added an external id field for the foreign DB, then those relationships can be preserved using \:.
 
parent_id=Parent\:external_id_field__c

Where "external_id_field__c" should be replaced by whatever the external id field's name is in your system's Account object.

The graphical data loader knows how to do this--but only on UPSERTs.  It will allow you to graphically identify the lookup-fields for relationships and if you save the mapping file, you'll see this notation inside it for each of the relationships.

I haven't found a lot of documentation on this feature of the data loader anywhere.

Let me know if this gets you closer.
jjLAjjLA
Great this helped a lot. Thanks!
jjLAjjLA
tggane, you've helped me a couple months ago, have you had any experience with Dataloader CLI and assigning Record Types dynamically? I think I could easily hardcode IDs, but this is not ideal. Any advice? Thanks!
Jonathan Hart 48Jonathan Hart 48
Thank you tggagne.  They really should add that to the documentation.  Your assistance here made my day!