Create and Link records using External Id using REST API

We will be using workbench as a tool in this this article. 

For example, you have two objects called ‘Reservation__c’ and ‘Address__c’. ‘Reservation__c’ object has lookup field called ‘Billing_Address__c’ that is lookup to ‘Address__c’. 

‘Address__c’ object has External Id field called ‘Location_Id__c’.

Assume that we already have records populated in Address objects. For example

IdStreet NameCityStateCountryZip CodeLocation Id
02i2D000002IggvQACGlenn RdAtlantaGAUSA330126714
02i2D000002IggvQACJorge RdMiamiFLUSA321426715

and While creating Reservation records, you want to link Reservation with Address records using external id i.e. Location Id. 

  • Open Workbench
  • Login to workbench.
  • Go to ‘Rest Explorer’ under ‘Utilities’ tab.
  • Select POST
  • Put ‘/services/data/v47.0/sobjects/Reservation__c/’ 
  • In the body put below JSON and click on Execute button.

Payload will looks like this:

{
"Name" : "UTB0502",
   "Address__r" :
   {
       "Location_Id__c" : "6714"
   }
}