0

I have applied a default pricebook to a set of users. When I try to add products to that opportunity the pricebook already shows that it is selected at the product selection screen but still pricebook2Id remains blank at the opportunity level. Due to which when my code tries to insert another product from the backend(for some other functionality) it throws the following error

(caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id, others must specify product id): [PricebookEntryId, unknown]).

On debugging I got to know that when PricebookEntryId is being assigned to the newly created product a check is happening for matching the (to be assigned) pricebookId with the pricebook2id present in the opportunity level which is null. So my code is not running in that part and throwing this error.

3
  • 1
    Is your trigger a before update/insert? Has the pricebook just not yet been set on the opportunity? Commented Oct 4, 2019 at 16:26
  • Yes It's before Insert.Only one pricebook is available for the opportunity so its by default assigned and on clicking 'Add Products' button user is taken to products selection page.
    – user74804
    Commented Oct 9, 2019 at 6:45
  • What object is the trigger on. I'd debug in a sandbox if you comment out your trigger, would this work correctly (minus the functionality your trigger provides) in terms of the product being inserted and the opp having a pricebook assigned. My assumption is that even though it might look like it's assigned on the selection page, it has not yet been saved into the database when you're doing your logic in the trigger. Commented Oct 9, 2019 at 10:58

0

You must log in to answer this question.

Browse other questions tagged .