The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

Must-read

Loading central bank exchange rates into Salesforce with Apex batch Jobs (opens in a new tab)

You will learn why DatedConversionRate cannot be written with Apex DML, how to convert a bank's rate table into your corporate currency, and how to schedule a callout-based sync with the right credentials.

Why read this

The post also lists setup errors that waste time.

  1. Scheduled Apex starts a batch job
  2. One GET to the rates API
  3. One REST write per currency
  4. Failures make the job fail
The batch sync runs one table per execute, with a single rates GET and then one REST write per currency

Salesforce multi-currency uses whatever rates are maintained under Manage Currencies, and it does not fill them in. Orgs often update rates by hand, so they drift from the figures finance books in the ERP. When a specific institution’s rate is required, such as the ECB or the Fed, a scheduled job can load the table and date each rate with the day the bank published it.

The post explains that DatedConversionRate cannot be written with plain DML and must be written through the REST API, which means an in-org job calls its own REST endpoint from Apex using a Named Credential. Salesforce closes the previous date range automatically, so the job must query for an existing row with the same StartDate and update it rather than insert a duplicate. Rates are stored as units of the currency per one unit of the corporate currency, and the post gives a formula for converting any bank’s table from its home currency into the corporate currency’s basis.

The post also covers the credential setup for both the rates API and the org’s own REST API, including External Client App steps, and lists pitfalls such as an empty Scope value and redacted tokens. For scheduling, Scheduled Apex cannot make callouts, so the schedulable starts a batch job with scope 1, and write failures should be made to fail the job so they appear under Apex Jobs. The author reports test results from a Developer Edition org and offers a Python alternative for teams that already run cron or CI jobs.

Read the original at dev.to (opens in a new tab)

Worth reading?