[SalesForce] Salesforce Custom Object lookup to Contact (or another custom object) and Data Loader import on email rather than id

I am new to Salesforce and hope to begin developing ASAP. I am currently testing a theory…I want to use either Contacts or a Custom Object which will have another Custom Object (Special Activities) related list. I want to populate the records in Special Activities from a CSV file, this is exported from an external system and will be uploaded via the DataLoader.

The Special Activities is related to Contacts (or the other objects) via a Lookup Relationship obviously on ID. I can display the email from the Contacts etc on Special Relationship via a formula field however my external export file only contains an email as a reference and a formula field does not allow me to map via the Data Loader (obviously)…Can anyone suggest how I get around this using Salesforce?

Thanks – unfortunately my current thinking means I have to export the Contact ID/Email to a file from Salesforce and then merge with the other csv file before reimporting into Salesforce using the ID – this is long winded and I would struggle to automate nicely.

EDIT : I found exactly the functionality I need via the dataloader.io site, see the link: https://dataloader.io/using-import-lookups. I would like to replicate this in dataloader to automate imports

Best Answer

I found Salesforce's own documentation pretty useful on Data Loader and relationships. Good enough to just copy verbatim (aside from minor formatting).

Description of Steps

  1. Add a Text field to your parent object. Make sure you set the length to 18 and mark it as an External Id.
  2. Export your parent records with the Id field included.
  3. When inserting parent records, make sure you map the Id to your newly created External Id field from Step 1.
  4. Upsert the child records based on Id. You can then set what External Id field to use as a lookup for each parent object. Select the field you created in Step 1.
  5. Optionally delete the field you created in Step 1.

Pros

  • Can be implemented via Data Loader (free)

Cons

  • Requires creation of a new Custom Field

Documentation referenced above:

  1. In the destination Organization, on the Parent Object (in this case, Account), create a new field of type Text and mark it as an ‘External Id’ field. Be sure to make the length of the field at least 18 characters (the size of the Salesforce ID field). Let’s call this new field on Account – ‘Source Acct ID’.
  2. Export the Parent Object (in this case, Account) data from the source Organization into a csv file using Data Loader. Be sure to include the ‘Id’ field when exporting this data.
  3. Insert the data from Step 2 into the destination Organization using Data Loader. In the mapping screen of Data Loader, map the ‘ID’ field from the csv file to the new field created in Step 1 (in this case, ‘Source Acct ID’).
  4. Export the Child Object (in this case, Opportunity) data from the source Organization into a csv file using Data Loader. Be sure to include the relationship field (in this case ‘AccountID’) when exporting this data.
  5. Upsert the data from Step 4 into the destination Organization using Data Loader. In Step 2a of the Data Loader, select ‘ID’ as the field to use for matching Opportunities. In Step 2b of the Data Loader, select the field created in Step 1 (in this case, ‘Source Acct ID’) as the field to match the parent object. In the next mapping step of the Data Loader, map the ‘AccountId’ column of the csv file to the ‘Account:Source Acct ID’ field. This will allow the Data Loader to associate each Opportunity record with its respective parent Account record. Note that the ‘AccountId’ column of the CSV file should NOT be mapped to the standard ‘AccountId’ field (which is what the Data Loader does by default with the ‘Auto-Match Fields to Columns’ option). Instead, it has to be mapped to the ‘Account:Source Acct ID’ field.
  6. After finishing the data import, the new field created in Step 1 (‘Source Acct ID’) may be deleted as it was only necessary for the data import process.