You need to sign in to do that
Don't have an account?
Ankit Kumar 169
Create New Price book 'Lenovo Pricebook' and 10 Products with Prices in the Pricebook :
My Code is :
public class PriceBookController {
public PriceBookController(){
Pricebook2 p = new Pricebook2();
p.name='Lenovo Pricebook2';
p.Description ='Pricebook with All product and Price';
p.IsActive = true;
insert p;
List<Product2> proList = new List<Product2>();
for(Integer i =0 ;i<10;i++){
Product2 pro = new Product2();
pro.Name = 'Lenovo'+ i;
proList.add(pro);
}
insert proList;
Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = proList[0].Id, UnitPrice = 1000, IsActive = true);
insert standardPBE;
PricebookEntry pb = new PricebookEntry();
pb.IsActive =true;
pb.Pricebook2Id =p.id;
pb.UseStandardPrice =false;
pb.UnitPrice =5001;
pb.Product2Id=proList[0].Id;
insert pb;
}
}
NOTE : It is only assign one product with standard pricebook and custom pricebook and for rest of the product they will not assign anything.
public class PriceBookController {
public PriceBookController(){
Pricebook2 p = new Pricebook2();
p.name='Lenovo Pricebook2';
p.Description ='Pricebook with All product and Price';
p.IsActive = true;
insert p;
List<Product2> proList = new List<Product2>();
for(Integer i =0 ;i<10;i++){
Product2 pro = new Product2();
pro.Name = 'Lenovo'+ i;
proList.add(pro);
}
insert proList;
Pricebook2 standardPB = [select id from Pricebook2 where isStandard=true];
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = standardPB.Id, Product2Id = proList[0].Id, UnitPrice = 1000, IsActive = true);
insert standardPBE;
PricebookEntry pb = new PricebookEntry();
pb.IsActive =true;
pb.Pricebook2Id =p.id;
pb.UseStandardPrice =false;
pb.UnitPrice =5001;
pb.Product2Id=proList[0].Id;
insert pb;
}
}
NOTE : It is only assign one product with standard pricebook and custom pricebook and for rest of the product they will not assign anything.