[SalesForce] Is it possible to configure currencies in a multi-currency scratch org

I'm writing SalesforceDX unit tests that need to use either USD or EUR in Account.currencyIsoCode. So I created a scratch org from this project-scratch-def.json configuration that specifies the MultiCurrency feature:

{
  "country": "US",
  "edition": "Developer",
  "features": ["MultiCurrency"],
  "orgPreferences": {
    "enabled": [
      "S1DesktopEnabled"
    ],
    "disabled": []
  },
  "orgName": "MyOrg",
  "adminEmail": "admin@my.org"
}

Running a test fails with this error:

System.DmlException: Insert failed. First exception on row 0;
first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Account Currency:
invalid currency code: EUR: [CurrencyIsoCode]

Turns out that creating an org with the feature MultiCurrency only has one currency (USD) configured, which can be checked in the developer console with:

SELECT IsoCode FROM CurrencyType

I googled, but couldn't find a way to configure the active currencies in the project-scratch-dev.json, so I figured I would just insert them in the tests themselves, like so:

static testMethod void testEuros() {
  List<CurrencyType> euros = [select IsoCode from CurrencyType where IsoCode = 'EUR'];

  if (euros.size() == 0) {
    CurrencyType euro = new CurrencyType();
    euro.IsoCode = 'EUR';
    euro.IsActive = true;
    euro.IsCorporate = false;
    euro.DecimalPlaces = 2;
    euro.ConversionRate = 1.0;
    insert euro;
  }

  Account acc = new Account();
  acc.Name = 'TestAccount';
  acc.CurrencyIsoCode = 'EUR';
  insert acc;
}

But this attempt is cut short by sfdx force:source:push refusing to push the source with the following error:

DML operation Insert not allowed on CurrencyType

So the question is… How does one properly configure currencies in a multi-currency scratch org?
Preferably in the project-scratch-def.json, but definitely without opening the org and making manual changes, that is.

Best Answer

Neither DML nor Metadata API support Currency (Exchange) Inserts.

The tree/bulk api does, though, see this answer for a programmatic way to enable different currencies in a scratch org:

How to prep scratch org with currencies

Related Topic