I am developing an external application which will insert & update products and their pricebook entries into Salesforce system.
In order to avoid maintaining the Salesforce ProductId in my external application, I created a new custom field
erpId__c on Product2 Object and marked it external. This way, I am able to successfully upsert products using Bulk API.
Now, I want to do the same with PriceBookEntry but it looks like while inserting pricebookentry, Salesforce ProductId is a required field.
Is there any way to avoid this limitation and create PriceBookEntry using my Product External Id?
I wrote below Apex code to quickly outline my problem but my real use-case will involve Bulk API.
PricebookEntry sp = new PricebookEntry(); sp.Pricebook2Id = '01s09000000kBb1AAE'; // standard pricebook sp.erpId__c = '67890'; sp.UnitPrice = 20000; insert sp;
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Product2Id]: [Product2Id]