Is it possible to upsert PBE records? According to the API document, upsert is a supported function. Now that we can create custom fields on the PBE, I even added an external ID field, but I cannot seem to get this to work. When I try to upsert, using the external ID field, I get this error "This price definition already exists in this price book".
I ran into a similar challenge on a previous project where existing PBE rows could not be "updated" if you are sending CurrencyIsoCode, Product2Id, or Pricebook2Id as part of your upsert call. If you look at the API guide, the updateable flag on those three fields is false. The workaround I implemented was as follows:
- Run initial upsert call with all fields on PBE. Existing records will error out because CurrencyIsoCode, Product2Id, and Pricebook2Id are not updateable fields. New records will insert correctly.
- Run the same upsert again but remove CurrencyIsoCode, Pricebook2Id, and Product2Id fields from your upsert call. This will allow the failed records from the first upsert call to be updated appropriately.
It's not the ideal workaround because you are essentially doubling your API calls but it worked well for what we needed.