+ Start a Discussion
Rahul H 4Rahul H 4 

product and pricebook

When upserting Quote Line Item, We want to able to pass an external reference id which is a product code and have Salesforce determine the corresponding price book entry id. We only have one pricebook we are using and we can pass that in a custom field if required

Can you please let us know how to do that?
Deepali KulshresthaDeepali Kulshrestha
Hi Rahul,
Following is the code involving pricebook product and pricebook entry refer to this:

    List<PricebookEntry> pbe = new List<PricebookEntry>();
    Pricebook2 pb =[select id from Pricebook2 where isStandard = true limit 1];
            for(integer i=0; i<prolist.size(); i++){
      PricebookEntry pbee = new PricebookEntry();
      pbee.UnitPrice = 1;
      pbee.Product2Id = prolist.get(i).id;
      pbee.Pricebook2Id = pb.id;
    insert pbe;

Hope this helps. If it does please mark it as best answer to help others too.
Thanks and Regards,
Deepali Kulshrestha