Skip to content

Instantly share code, notes, and snippets.

@sfdcfanboy
Last active November 6, 2017 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfdcfanboy/fc595afc878e1c7e65127237b1677fa5 to your computer and use it in GitHub Desktop.
Save sfdcfanboy/fc595afc878e1c7e65127237b1677fa5 to your computer and use it in GitHub Desktop.
//product1
Product2 p = new Product2();
p.Name = 'Test Product';
p.Description = 'Test desc';
p.IsActive = true;
insert p;
//standard price book entry for Product p
PricebookEntry pbe1 = new PricebookEntry();
pbe1.Pricebook2Id = Test.getStandardPricebookId();
pbe1.IsActive = true;
pbe1.Product2Id = p.Id;
pbe1.UseStandardPrice = false;
pbe1.CurrencyISOCode = 'SGD';
pbe1.UnitPrice = 100;
insert pbe1;
//custom pricebook
PriceBook2 pb = new PriceBook2();
pb.Name = 'Custom PB';
pb.IsActive = true;
insert pb;
//custom pricebook entry for p1
PricebookEntry pbe = new PricebookEntry();
pbe.Pricebook2Id = pb.Id;
pbe.IsActive = true;
pbe.Product2Id = p.Id;
pbe.UseStandardPrice = false;
pbe.CurrencyISOCode = 'SGD';
pbe.UnitPrice = 100;
insert pbe;
//update Pricebookentry to use Standard Price
pbe.UseStandardPrice = true;
update pbe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment