Last active
September 26, 2023 21:31
-
-
Save benedwards44/1b1958048c8be96e346fd87e9d24b22d to your computer and use it in GitHub Desktop.
Price Book Entry Creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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