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
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];
    System.debug('Pricebook-->'+pb);
            
            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;
      pbe.add(pbee);
    }
    insert pbe;


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