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)


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 '16 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.