How to link or relate records using External Id Field in Salesforce?

How to link or relate records using External Id Field in Salesforce?

Parent Object:

Child Object:


Sample Code to link or relate child record without Standard Id field:
Parent__c objParent = new Parent__c( External_Id__c = ‘test1’ );
insert new Child__c(
    Name = ‘Testing’,
    Parent_External_Id__c = ‘test1’,
    Parent__r = objParent
);
Output:
 


Leave a Reply