i want to add product price into PricebookEntry object with help of following APEX code:

PricebookEntry pBook = new PricebookEntry(UnitPrice = price,
                                          Product2 = productId
insert pBook;

but when i try to save my code then it gave me following error:

Invalid initial expression type for field Product2, expecting: Product2 (or single row query result of that type)

1 Answer 1


I believe you are receiving the error as you are trying to assign an ID to object placeholder.

Please try using Product2Id = productId instead of Product2 in your code.


  • 1
    thanks manjit my code is working now. thanks for you valuable comment
    – Rajinder
    May 20, 2016 at 11:23

You must log in to answer this question.

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