I have a contact object and a custom object called "Product User"

The Contact is the parent and the "Product User" is the child.

I already have Contact data and I am looking for Upserting records in "Product User" using Simple-Salesforce or the Salesforce REST API.

I have a script containing "Product User" fields and since "Id" is required for the Parent Lookup, I have grabbed the "Contact External ID" from Contact object which holds the external unique Contact ID from our web app that we want to use for creating that lookup relationship.

How can we create the lookup relationship by leveraging something like [ObjectName]:[ExternalIDField__c] for the Salesforce API on upsert calls. Ideally, we would then create a net new contact when the external ID does not exist and then reparent after successful insertion from the REST API.

1 Answer 1


Simple Salesforce is a basic Salesforce.com REST API client built for Python.

Supposing that the Contact object has a custom external id field called customExtIdField__c, you can upsert a record with an external id 11999 with the following command.

sf.Contact.upsert('customExtIdField__c/11999',{'LastName': 'Smith','Email': '[email protected]'})

The Simple Salesforce documentation doesn't state anything about upserting records and associating with an existing record using its external id. However, since it uses Salesforce.com REST API you should have a look at the documentation page.

The following example creates a record and associates it with a parent record via external ID. It assumes the following:

  • A Merchandise__c custom object that has an external ID field named MerchandiseExtID__c.
  • A Line_Item__c custom object that has an external ID field named LineItemExtID__c, and a relationship to Merchandise__c.
  • A Merchandise__c record exists that has a MerchandiseExtID__c value of 123.
  • A Line_Item__c record with a LineItemExtID__c value of 456 does not exist. This is the record that gets created and associated to the Merchandise__c record.
sf.Line_Item__c.upsert('LineItemExtID__c/456',{'Name': 'LineItemCreatedViaExtID','Merchandise__r': {'MerchandiseExtID__c': 123}})
  • can we do smart lookup using simple-salesforce library?
    – Cloud Man
    Commented Sep 6, 2022 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .