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
RhondaBRhondaB 

updating pricebook2id of an opportunity

Hi, I have an application where the user can choose between several pricebooks, add some products that get uploaded to SF.com. The first time the user does this, it works fine but if the go back to the begininning of the same record and change the pricebook it fails because the pricebook in SF.com is different. It deletes all the existing products but won't add the new ones. I need to be able to update the opportunity with the new pricebook2id. How can I do this? I'm using C#.

Thanks,

Rhonda
DevAngelDevAngel
Change a pricebook on an opportunity must remove all the line items. There can be no assumption made as to the existence of products from one price book to the other. If you are keeping several pricebooks synched you can do this with an scontrol that reads the lineitems prior to changing the pricebook, and then recreate the lineitems using the new pricebook id.
RhondaBRhondaB
This was originally posted a long time ago.  I am still having this issue.
 
1)  I go in and delete all the existing products (which works)
sForce.DeleteResult[] deleteResults = binding.delete(IDs);
 
2)  Change the pricebook2id to the new one (doesn't work)

sForce.Opportunity oop = new sForce.Opportunity();

oop.Id = oppId;

oop.Pricebook2Id = sThisPBId;

sr = binding.update(new sForce.sObject[] {oop})[0];

3) Try to add the new line items (doesn't work);

How can I get this to work.  If it is a new opportunity that doesn't have a pricebook already selected or has the correct pricebook selected, it works fine.  It only fails if this is an old opportunity that uses one of the older pricebooks.

Thanks,

 

Rhonda