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
D srinivas 8734D srinivas 8734 

i have to store pricebook name in custom setting from their i have to query the pricebook & create pricebookentry for that?

i am importing products from other system into salesforce ,
i have to store pricebook name in custom setting from their i have to query the pricebook & create pricebookentry for each and every imported products ,
can anyone assist me ?
Mukesh Kuamr LalMukesh Kuamr Lal
Hi D srinivas 8734,

First create a pricebook and then Instead of pricebook name store pricebookId in the custom setting.

Step 1
String pricebookId = get id from custom setting.
ImportedProductList = import and insert all the products (Product2) from other system.

Step 2
List<PricebookEntry> pricebookEntryList = new List<PricebookEntry>();
PricebookEntry pricebookEntryRecord;
for (ImportedProduct p : ImportedProductList) {
   pricebookEntryRecord = new PricebookEntry();
   pricebookEntryRecord.Product2Id = p.Id;
   pricebookEntryRecord.Pricebook2Id = pricebookId;
   pricebookEntryList.add(pricebookEntryRecord);
  //set other fields as per requirement.
}
if (pricebookEntryList.size() > 0) {
   insert pricebookEntryList;
}

Hope this help you !!

Thanks,
M K Lal