I want to upsert objects through the .NET-ForceClient into our Salesforce, more specifically, I want to insert or update an object that contains a reference to another object.

As a simple example, let's take a look at an Account-object, which has a Reference to a RecordType-object through its RecordTypeId.

What is the best practice to upsert such an object, preferably without

  • querying all the RecordTypes first,
  • then extract the RecordTypeId for a given RecordType
  • and finally calling an upsert with the manually extracted RecordTypeId?

Is there any way to call an insert/update/upsert across multiple objects like one would do in a traditional relational database? How can this be achieved?

  • You can't have two different accounts with the same info (name and Id) with different RecordTypes. I think you're chasing a red herring. If there's a match with the info you've provided, you'll get an update. If not, you'll get an insert. If you want a specific Record Type for the account, you'll need to know what that is. You can update an existing account to change it's Recordtype.
    – crmprogdev
    Dec 6, 2016 at 14:42
  • I think you didn't get the essence of my question or I wasn't able to bring it accross: I want to know how I can create (or update) an account object through the API without providing the RecordTypeId, but rather provide the RecordType itself!
    – Christian
    Dec 6, 2016 at 20:32

1 Answer 1


It doesn't work so well with the Account-RecordType relationship, but you use an External ID from a related record to create the relationship during an upsert. See Import related records using an External ID.

So, if you were inserting a Contact and you knew the External ID for the Account you could insert the Contact and relate it to that Account without first having to query the Account ID.

This is also covered in create() and Foreign Keys

You can use external ID fields as a foreign key, which allows you to create a record and relate it to another existing record in a single step instead of querying the parent record ID first. To do this, set the foreign key field to an instance of the parent sObject that only has the external ID field specified. This external ID should match the external ID value on the parent record.

You must log in to answer this question.

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