Skip to content

Instantly share code, notes, and snippets.

@benedwards44
Last active September 26, 2023 21:31
Show Gist options
  • Select an option

  • Save benedwards44/1b1958048c8be96e346fd87e9d24b22d to your computer and use it in GitHub Desktop.

Select an option

Save benedwards44/1b1958048c8be96e346fd87e9d24b22d to your computer and use it in GitHub Desktop.
Price Book Entry Creation
List<String> enbabledCurrencies = new List<String>();
for (CurrencyType currency :[SELECT IsoCode FROM CurrencyType WHERE IsActive = true]) {
enbabledCurrencies.add(currency.IsoCode);
}
List<PricebookEntry> pbesToCreate = new List<PricebookEntry>();
for (Product2 prod :[SELECT Name, (SELECT CurrencyIsoCode FROM PricebookEntries) FROM Product2]) {
for (String currencyCode :enbabledCurrencies) {
Boolean pbeExistsForCurrency = false;
for (PricebookEntry pbe :prod.PricebookEntries) {
if (currencyCode == pbe.CurrencyIsoCode) {
pbeExistsForCurrency = true;
break;
}
}
if (!pbeExistsForCurrency) {
pbes.add(new PricebookEntry(
Product2Id = prod.Id,
IsActive = true,
CurrencyIsoCode = currencyCode,
Pricebook2Id = '01sj0000003HjbWAAS',
UnitPrice = 0,
Name = prod.Name
));
}
}
}
insert pbesToCreate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment