You need to sign in to do that
Don't have an account?

Handling a small CSV Importing using relationships and external IDs
Hey all.
I am building a small system that can import CSV files emailed to it. There are 3 objects involved, Accounts (a person account), and two custom objects, Auto, and Ownership. The import is responsible for creating ownership records (simply a junction object between an account and an auto).
So the Ownership has a master detail relationship with both Account and Auto. The account has a field called SSN, and the auto has a field called VIN. These are both marked as external IDs.
Account Ownership Auto
SSN <---------- Account | Auto------------------> VIN
The question becomes how can I create an owernship record from my import file that contains a SSN and a VIN. Can you populate a lookup field with an external ID, or will I need to run a query first and populate the lookup relationships with the Id's from the query? I'd like to avoid having to query to save on performance and potential governor limits, but I know that may not be doable. In that case I'd like just build a set of SSN and VIN and do one query for each object type using the IN() SOQL operator correct?
Thanks for any insight!
Have you tried using relationships?
new bridgeObject(lookup__r.ExternalId = 'xyz', lookup2__r.externalId = 'abc');
upsert bridgeObject;
or
ref1 = new object(externalId__c = 'xyz');
new bridgeObject(lookup__r = ref1);
upsert bridgeObject;
I have had mixed success with those approaches.
All Answers
Have you tried using relationships?
new bridgeObject(lookup__r.ExternalId = 'xyz', lookup2__r.externalId = 'abc');
upsert bridgeObject;
or
ref1 = new object(externalId__c = 'xyz');
new bridgeObject(lookup__r = ref1);
upsert bridgeObject;
I have had mixed success with those approaches.
Cool, thank you, that is the kind of info I was looking for. I didn't know if you could populate a lookup with external id data and have it work. I know I could have just tried, but I know I won't get it right the first few times, so I wanted to make sure it could be done so I don't give up :P Thank you!