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
trinitytrinity 

Update PriceBookEntryID after the Opportunity Line has already been created

I am trying to update PriceBookEntryID of an already created OpportunityLineItem. I am getting this error:

 

caused by: System.SObjectException: Field is not writeable: OpportunityLineItem.PricebookEntryId

 

Is it possible to update PriceBookEntryID after the OpportunityLineItem has already been created?

Vanessa BarrosVanessa Barros

the field that you are trying to update is the primary key of the object.

The field is "closed", cant not be editable.

Vanessa BarrosVanessa Barros

but.. what are u trying to do?

 

 

trinitytrinity

We are trying to change the product in Opportunity Line Item after it is created with some other product. Deleting and creating again takes significant amount of time in our instance because we have some custom code attached to Opportunity Line Item that adds additional steps in creation.

 

Vanessa BarrosVanessa Barros

can u put your code please? its must easier.

lnryanlnryan

Is there a reason you're not using a before insert trigger. That's generally where you put logic that catches one association and redirects it to another...

 

If this is something that's going to occur at anytime in the sales process based on conditional logic (ie on lineitem updates, not inserts) there's no way to avoid a clone - delete original - insert clone pattern except perhaps to reevaluate why you're replacing the pricebook entry in the first place. if it's for discounting logic, best to extend the opportunity line item rather than define separate pricebook entries.

Vanessa BarrosVanessa Barros

u have to delete the record first, keep the information in code that u want to reuse in the new line item with the new product