Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 8 down vote accepted

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.

share|improve this answer
    
Is it a requirement for the External ID to be unique for the import to work? Or is it just Best Practice? –  Salesforce Wizard Aug 9 '12 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. –  David Gillen Aug 9 '12 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=...));

share|improve this answer

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'
})
share|improve this answer

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.

share|improve this answer
2  
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 Jan 6 '13 at 18:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.