1

I'm currently developing a system which, among other things, will act as a proxy for Salesforce's APIs.

We may occasionally want/need to send a collection of new and updated data through the proxy into Salesforce. When it is an update, we will already have the Salesforce Ids and have no need to use alternatives which would actually complicate things.

Is it possible for us to do an upsert multiple records synchronously over an API, similar to how upsert works in DML? Or would we need to split this into multiple requests?

1 Answer 1

5

Yes, you're allowed to upsert against a Salesforce ID. You can read more about this in the various documentations, such as REST and SOAP. In fact, in some objects, you can even use the Name field, as long as the idLookup property is true for that field. In fact, the documentation even calls this out explicitly:

This example uses the POST method as a special case to insert a record where the Id field is treated as the external ID. Because the value of Id is null, it’s omitted from the request. This pattern is useful when you’re writing code to upsert multiple records by different external IDs and you don’t want to request a separate resource. POST using Id is available in API version 37.0 and later.

Note that each documentation calls out a minimum API version. This shouldn't matter since you're doing a new integration, just calling it out so it's not accidentally overlooked.

Here's an Upsert example from the Workbench:

Upsert Example

This uses the PATCH /composite/sobjects/<sObjectName>/<externalId> method of Upsert. This method supports 200 records per call.

7
  • Cheers for the response. It seems I missed an important word in my question: "Multiple". I want to be able to send a mix of inserts and updates over the API, same as I might do an upsert from within Salesforce/Apex. If I understand the above links correctly, they are only intended to submit one record at a time, but if I look at "Using Composite Resources", upsert seems to require an external Id. Commented Jan 19, 2021 at 8:28
  • 1
    @BrianKessler Upsert doesn't require an External ID, that's just how the examples are written. Try this example?
    – sfdcfox
    Commented Jan 19, 2021 at 10:10
  • I think I'm missing something since this example i update and it is also splitting every request into a new request within a composite request. But I'm looking for something more like developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… or developer.salesforce.com/docs/atlas.en-us.api_rest.meta/… ... but upsert. Commented Jan 19, 2021 at 10:23
  • 1
    @BrianKessler Added example.
    – sfdcfox
    Commented Jan 19, 2021 at 10:30
  • 1
    @BrianKessler Yep. Glad I could get it sorted out for you.
    – sfdcfox
    Commented Jan 19, 2021 at 10:37

You must log in to answer this question.

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