๐Ÿ”— How to Handle Lookup Relationships When Importing Data - Solution for Guru

Table of Contents
< All Topics
Print

๐Ÿ”— How to Handle Lookup Relationships When Importing Data

When importing data into Salesforce, handling lookup relationships properly is essential to maintain data integrity and ensure correct linking between objects like Accounts, Contacts, Opportunities, and custom objects.

This guide explains how to import records that include lookup fields, ensuring they correctly relate to existing Salesforce records.


๐Ÿ“˜ What Is a Lookup Relationship?

A lookup relationship in Salesforce links one object to another. For example:

  • A Contact may have a lookup to an Account.
  • A Custom Object may have a lookup to a User or another custom object.

During import, these links must reference the correct Record ID or a unique external identifier.


๐Ÿงฐ Tools You Can Use

ToolSupports Lookup Relationships?Best For
Data Import Wizardโœ… (with limitations)Basic imports, standard objects
Data Loaderโœ… (more flexibility)Large volumes, custom objects
Dataloader.ioโœ… (user-friendly)Cloud-based data handling
API/Bulk APIโœ… (programmatic control)Automated or complex imports

๐Ÿ“ Step-by-Step: Handling Lookup Relationships During Import

Option 1: Use Salesforce Record IDs

This is the most direct and reliable method.

๐Ÿ”น Example: Importing Contacts with Account Lookup

FirstNameLastNameAccountId
JohnDoe0015g00000abcdef123
JaneSmith0015g00000ghijkl456

Steps:

  1. Export existing Accounts to get their Record IDs.
  2. Include those IDs in the import CSV under the AccountId column.
  3. Use Data Loader or Data Import Wizard to upload the Contacts.

โœ… Pros: Accurate, avoids duplicate matches
โš ๏ธ Cons: You must obtain and manage record IDs

Option 2: Use External IDs

If you don’t want to rely on Salesforce record IDs, use a field marked as an External ID.

๐Ÿ”น Example: Importing Contacts with Account lookup via External ID

Assume your Account object has a field called External_Account_Code__c marked as External ID.

FirstNameLastNameAccount:External_Account_Code__c
JohnDoeACC001
JaneSmithACC002

Steps:

  1. Ensure the related objectโ€™s External ID field is unique and indexed.
  2. In your CSV, use the syntax:
    ObjectName:ExternalID_Field__c (e.g., Account:External_Account_Code__c)
  3. Import via Data Loader or Dataloader.io with mapping.

โœ… Pros: More human-readable, no need for record ID
โš ๏ธ Cons: External ID must be unique and already exist in Salesforce


๐Ÿ”„ Using Data Loader for Lookup Imports

  1. Prepare Your CSV with either:
    • Record IDs (AccountId)
    • External IDs (Account:External_ID__c)
  2. Open Data Loader
    • Choose Insert or Upsert
  3. Map Fields
    • Ensure your lookup field is mapped correctly to either the ID or External ID
  4. Run Import
    • Review success and error files

๐Ÿ” Tips & Best Practices

  • Always load parent records first (e.g., Accounts before Contacts).
  • If using External IDs, make sure they are:
    • Marked as External ID in field settings
    • Populated in the system before import
  • Test a small sample before full import
  • Use Upsert instead of Insert to avoid duplicates
  • Keep backup of your original data

โ“ FAQs

Q: What if the referenced record (lookup) doesnโ€™t exist?
A: The row will fail to import. Load parent data first, or use Upsert.

Q: Can I create lookup records during the same import?
A: Not directly. You must import parent records first, then the child.

Q: Can I use the Data Import Wizard for custom object lookups?
A: Only if the lookup is to a standard object and the external ID is properly set.