I have a location field on Opportunity which is tied up with a pricebook. If I clone the Opportunity with products, it won't allow me to change the location because it's associated to that pricebook. Now how do I clone an Opp with products and change the location so that will set the pricebook to that corresponding location on the cloned Opp?

Highly appreciate any help.

  • 1
    so Opportunity.pricebook2Id is set by some trigger based on Opportunity.location__c ? You may need to override the OOB Clone button to present a VF form wherein user can enter Location__c and then you do the heavy lifting of cloning OLI in the VF controller. – cropredy Jul 31 '15 at 20:55

You cannot clone an Opportunity with Products and also change the Price Book while keeping the Products because the OpportunityProducts aren't just OpportunityProducts - they also contain a reference to a Price Book Entry record. So the system cannot just change the Price Book because there is no system rule that enforces that the same "Products" (Price Book Entry - Product relationships) exist in every Price Book.

You will need to write a script to do a custom clone that will find the Price Book Entries in the new Price Book that correspond to the Opportunity Product Price Book Entries in the old one, and will then attach those to the Opportunity.

Quite complicated, as you can see! For more information, see https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_products.htm.

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.