I want to use external id to reference a parent record on a lookup field. The problem is if this external id can't target that record, I just want to leave that lookup field a null.
Contact ct = new Contact(LastName = 'Smith',
FirstName = 'John',
Account = new Account(ExternalId__c = 'xxxxxxx'));
Assuming that ExternalId__c
from Account
sObject is set as EXTERNAL ID
. I want to upsert ct
no matter Account field has a value or not. What should I do with this?
I can also do it in a complex way but that will make no sense to use external id.
Contact ct = new Contact(LastName = 'Smith',FirstName = 'John');
List<Account> accList = [select id from Account where externalId__c = 'xxxxxxx'];
if(accList.size()==1){ct.Account = accList[0].id}
insert ct;
'xxxxxxx'
come from?