function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepa SekarDeepa Sekar 

pricebookentryId field not writeable

Requirement: To remove existing OLI and reinsert with new totalPrice,UnitPrice,ProductCode,Product2ID, pricebookentryId obtained from Integration.
Steps:
1. List<OLI> oldRecords = new List<OLI>();
2. List<OLI> newRecords = oldRecords;
3 Modified the TotalPrice, UnitPrice added a debug statement and I get the new Prices.
4. Now I try to update the productCode, Product2ID and pricebookentryID 
and get "Field is not writeable: OpportunityLineItem.PricebookEntryId".

Kindly suggest steps to overwrite "ProductCode,Product2ID, pricebookentryId" in apex class
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Deepa,

You cannot specify Product2Id  while creating an OLI. Only specify the PricebookEntryId.

Refer the below link.

https://developer.salesforce.com/forums/?id=9060G0000005muNQAQ

If this helps, Please mark it as best answer.

Thanks!!
Deepa SekarDeepa Sekar
Ankaiah,
Thanks for the prompt reply but I am unable to edit PricebookEntryId as well.