+ Start a Discussion
hylim1215hylim1215 

how to add pricebook id to opportunitylineitem?

during lead convert, it can create opportunity automatically. however, during opportunity creation, it does not update opportunity product's pricebook id. from documentation, opporunity product is accessing opportunitylineitem. is there a way to set opportunitylineitem's pricebook id? i tried setting its PricebookEntryId but it does no reflect changes. anyone can give some hints? thanks.

Baktash H.Baktash H.

hey wkwong,

 

i think you need a trigger for the lead conversion. There you can do everythink what you want with the created opportunity.

cropzimcropzim

Lead Conversion will create/update Account, create/update Contact, and optionally create Opportunity.

 

To set Opportunity.pricebook2Id (which is required to create Opportunity Products) you have this option:

  • Write an afterUpdate Apex trigger on Lead. This gives you access to the converted/created Opportunity ID and thus can fetch any other Account, Contact, Opportunity fields populated by Lead field mapping. From these, you may have enough information to derive the Pricebook2Id field based on application logic

You can not use Workflow/Field Update as Opportunity.pricebook2Id is not available to update using Field Update