I have a bunch of data I want to import into a custom object. I need these records to have a look up to the Account.

The Account has an External ID which is also present in the data I'm importing. Can I create child records referencing the External ID and not the Account ID?

This will be a fairly frequent data import so I would rather not have to do any manual matchup in Excel to get the Account ID.

The only option I can think of is to import with External ID listed in my custom Object and run a batch Apex job to do the referencing and populate the lookup field with the Account ID.

4 Answers 4


Yes, using the data loader you can look up to another record based on an external ID. However, note that the ID should be flagged as unique too.

This would also be doable via the API.

  • Is it a requirement for the External ID to be unique for the import to work? Or is it just Best Practice? Commented Aug 9, 2012 at 16:17
  • 1
    No, it is not a requirement; however, if two records exist with the same external ID, Salesforce will not know which one to associate the child record with and will throw an error. Commented Aug 9, 2012 at 16:19

Data loader is your friend, and has functionality geared for this specific requirement. In addition, if you were loading from a batch process like you mentioned, you'd create your objects in a fashion similar to new MyObject__c(My_Relationship__r = new My_Relationhip_c(MyExternalIdField_c=...));


Yes. For example, using the REST API and the forcetk library you would pass an Account object with the external id field populated:

client.create('Contact', {
  Account__r: {External_Id__c: 'my account id'},
  FirstName: 'Salesforce Wizard'

Using dataloader.io, you can do an import and use the lookup functionality to find the correct record. For example, let's say you have the account external ID and are inserting into Contacts. On the mapping screen, map the external ID to "Account ID." Then choose the select box which says "Lookup using Account" and select the external ID field.

For more information, see this overview of the lookup capabilities.

  • 5
    Dan - your relation to dataloader.io should be clear in your profile. Please update it to say you are an employee of the company. And make sure future answers of you have 'LESS' of a marketing scent.
    – Saariko
    Commented Jan 6, 2013 at 18:48

You must log in to answer this question.

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