Automate Currency Exchange Rate Updates in Salesforce using Currency Exchange API

Advertisements

Last Updated on August 6, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can you leverage Currency Exchange API to automatically update exchange rates on a daily basis in Salesforce using Salesforce Flow

Objectives:

After reading this blog, you’ll be able to:

  • Create Named Credentials for outbound requests.
  • Make an external callout from Scheduled-Triggered Flow.
  • Address the character limit restriction of flow formulas (3900 characters).
  • Update DatedConversionRate for multiple currencies.
  • Configure the currency API Key to retrieve up-to-date exchange rates, considering the base currency.
  • Initiate an outbound HTTP GET request utilizing Salesforce Flow, eliminating the need for coding.
  • Manage the outbound request response and implement appropriate actions.
  • Validate the integration and ensure the data flow works correctly.
  • and much more

👉 Previously, I’ve penned several posts on the topic of interfacing Salesforce with a diverse range of systems. Why not check them out while you are at it?!

  1. Generate Barcode and QR Code in Salesforce
  2. Integrate Salesforce with OpenWeatherMap Using Salesforce Flow
  3. Verify and Standardize Salesforce Addresses with Google’s Address Validation API
  4. Salesforce and Google’s Time Zone API Integration: Translating Coordinates into Time Zone Info
  5. Proactive Salesforce Monitoring: Periodically Checking if Salesforce is Down with the Salesforce Trust API

Business Use case

Madison Campbell currently serves as a Salesforce Architect at Gurukul On Cloud (GoC). Madison has been instrumental in incorporating multi-currency functionality into Salesforce as part of the Sales Cloud rollout. Due to the fact that Salesforce doesn’t offer any service to update the exchange rates automatically, GoC has opted to invest in Currency API licenses to access real-time exchange rates.

Madison’s current project involves setting up an automated process set to run each day at 12:53 AM, with the aim to:

  1. Make a callout to Currency API to retrieve up-to-date exchange rates.
  2. Update the latest exchange for active currency for the current date.

What is Currency Conversion API?

When engaging with international clients, it’s critical to have up-to-date currency information due to the fluctuating nature of exchange rates. Nevertheless, tracking these changes manually can be daunting. A viable solution is to leverage a Currency Conversion API. This service fetches real-time exchange rates seamlessly and integrates smoothly into the Salesforce ecosystem, ensuring accurate and current financial data for global transactions.

A Currency Conversion API is a web service that provides real-time or historical exchange rates for different currencies. These APIs can be used in applications, websites, or systems to convert a specified amount of one currency into another currency.

Here’s a high-level overview of how a currency conversion API typically works:

  1. The user provides two types of currency (the base currency and the target currency (optional)) and sometimes the amount of money they want to convert.
  2. The API then connects to a database or another API, which maintains up-to-date or historical information about exchange rates.
  3. The API fetches the current (or historical, if supported and requested) exchange rate using the provided base and target currencies.
  4. This information is returned to the user in a structured data format like JSON or XML.

These APIs can have various features. For instance, some offer real-time rates, while others provide historical rates. Some may provide information like country details, currency symbols, or economic indicators. The specifics depend on the particular API service.

It’s important to note that while some currency conversion APIs are free to use, others might charge fees or have usage limits. Always review the terms of use before integrating an API with your application.

How Does Currency API Work?

This blog post will use currencyapi.com to retrieve the latest exchange rates. Currency API is a reliable currency exchange API that helps you with current and historical foreign exchange conversions in over 170 currencies. With an update frequency of every 60 seconds, it offers real-time foreign exchange quotes and a stable design built to handle millions of requests per day.

The tool uses JSON REST API to provide real-time foreign exchange rates. Currency API offers a free API key. It gives you 300 free credits per month.
This endpoint returns currency exchange data for any given base currency (default USD). Remember, the base_currency and currencies parameters are optional in the request URL.
  1. base_currencyThe base currency to which all results are behaving relative to. By default, all values are based on USD.
  2. currenciesA list of comma-separated currency codes you want (EUR, USD, CAD). By default, all available currencies will be shown.
https://api.currencyapi.com/v3/latest?base_currency=USD&apikey=YOUR_API_KEY

In the request URL above, replace YOUR_API_KEY with your actual API key.

Here is a sample response in JSON format that the API might return:


{
   "meta":{
      "last_updated_at":"2023-07-13T23:59:59Z"
   },
   "data":{
      "ADA":{
         "code":"ADA",
         "value":2.8086044364
      },
      "AED":{
         "code":"AED",
         "value":3.6731121252
      },
      "AFN":{
         "code":"AFN",
         "value":86.18386231
      },
      "ALL":{
         "code":"ALL",
         "value":92.7498788235
      },
      "AMD":{
         "code":"AMD",
         "value":387.0996327635
      },
      "ANG":{
         "code":"ANG",
         "value":1.8019141509
      },
      "AOA":{
         "code":"AOA",
         "value":827.4984875378
      },
      "ARS":{
         "code":"ARS",
         "value":264.3404754682
      },
      "AUD":{
         "code":"AUD",
         "value":1.4518439119
      },
      "AVAX":{
         "code":"AVAX",
         "value":0.0711165273
      },
      "AWG":{
         "code":"AWG",
         "value":1.802502885
      },
      "AZN":{
         "code":"AZN",
         "value":1.6957974366
      },
      "BAM":{
         "code":"BAM",
         "value":1.7503471995
      },
      "BBD":{
         "code":"BBD",
         "value":2.0186559053
      },
      "BDT":{
         "code":"BDT",
         "value":108.7456953607
      },
      "BGN":{
         "code":"BGN",
         "value":1.7423235126
      },
      "BHD":{
         "code":"BHD",
         "value":0.3770421337
      },
      "BIF":{
         "code":"BIF",
         "value":2835.0034962064
      },
      "BMD":{
         "code":"BMD",
         "value":1.0000011732
      },
      "BNB":{
         "code":"BNB",
         "value":0.0039471663
      },
      "BND":{
         "code":"BND",
         "value":1.3254244144
      },
      "BOB":{
         "code":"BOB",
         "value":6.9081973779
      },
      "BRL":{
         "code":"BRL",
         "value":4.7966018527
      },
      "BSD":{
         "code":"BSD",
         "value":0.9997508873
      },
      "BTC":{
         "code":"BTC",
         "value":3.18409e-5
      },
      "BTN":{
         "code":"BTN",
         "value":82.7875795686
      },
      "BWP":{
         "code":"BWP",
         "value":13.146609164
      },
      "BYN":{
         "code":"BYN",
         "value":2.5235867498
      },
      "BYR":{
         "code":"BYR",
         "value":19600.026287661
      },
      "BZD":{
         "code":"BZD",
         "value":2.0152807543
      },
      "CAD":{
         "code":"CAD",
         "value":1.3112980739
      },
      "CDF":{
         "code":"CDF",
         "value":2460.0066527812
      },
      "CHF":{
         "code":"CHF",
         "value":0.8591875983
      },
      "CLF":{
         "code":"CLF",
         "value":0.0293540459
      },
      "CLP":{
         "code":"CLP",
         "value":809.9617685184
      },
      "CNY":{
         "code":"CNY",
         "value":7.1510014373
      },
      "COP":{
         "code":"COP",
         "value":4099.0103263252
      },
      "CRC":{
         "code":"CRC",
         "value":545.0305782376
      },
      "CUC":{
         "code":"CUC",
         "value":1.0000020691
      },
      "CUP":{
         "code":"CUP",
         "value":26.5000546451
      },
      "CVE":{
         "code":"CVE",
         "value":98.8499195565
      },
      "CZK":{
         "code":"CZK",
         "value":21.1847334147
      },
      "DJF":{
         "code":"DJF",
         "value":177.7206043129
      },
      "DKK":{
         "code":"DKK",
         "value":6.6396154285
      },
      "DOP":{
         "code":"DOP",
         "value":55.7502849904
      },
      "DOT":{
         "code":"DOT",
         "value":0.1807846775
      },
      "DZD":{
         "code":"DZD",
         "value":134.7195382877
      },
      "EGP":{
         "code":"EGP",
         "value":30.9014917254
      },
      "ERN":{
         "code":"ERN",
         "value":15.0000601861
      },
      "ETB":{
         "code":"ETB",
         "value":54.6598352276
      },
      "ETH":{
         "code":"ETH",
         "value":0.0004987864
      },
      "EUR":{
         "code":"EUR",
         "value":0.891017019
      },
      "FJD":{
         "code":"FJD",
         "value":2.1806014128
      },
      "FKP":{
         "code":"FKP",
         "value":0.7617154267
      },
      "GBP":{
         "code":"GBP",
         "value":0.7617210672
      },
      "GEL":{
         "code":"GEL",
         "value":2.5750282446
      },
      "GGP":{
         "code":"GGP",
         "value":0.7617151901
      },
      "GHS":{
         "code":"GHS",
         "value":11.3976463289
      },
      "GIP":{
         "code":"GIP",
         "value":0.7617153359
      },
      "GMD":{
         "code":"GMD",
         "value":59.6498345771
      },
      "GNF":{
         "code":"GNF",
         "value":8655.0213791449
      },
      "GTQ":{
         "code":"GTQ",
         "value":7.8407524782
      },
      "GYD":{
         "code":"GYD",
         "value":209.1700733677
      },
      "HKD":{
         "code":"HKD",
         "value":7.8214642531
      },
      "HNL":{
         "code":"HNL",
         "value":24.7197779189
      },
      "HRK":{
         "code":"HRK",
         "value":6.7238762909
      },
      "HTG":{
         "code":"HTG",
         "value":137.4736064516
      },
      "HUF":{
         "code":"HUF",
         "value":333.0809351337
      },
      "IDR":{
         "code":"IDR",
         "value":14964.534504828
      },
      "ILS":{
         "code":"ILS",
         "value":3.6145743181
      },
      "IMP":{
         "code":"IMP",
         "value":0.7617148319
      },
      "INR":{
         "code":"INR",
         "value":82.0312569983
      },
      "IQD":{
         "code":"IQD",
         "value":1310.0017588137
      },
      "IRR":{
         "code":"IRR",
         "value":42275.103111173
      },
      "ISK":{
         "code":"ISK",
         "value":130.890332185
      },
      "JEP":{
         "code":"JEP",
         "value":0.761715204
      },
      "JMD":{
         "code":"JMD",
         "value":154.7112617335
      },
      "JOD":{
         "code":"JOD",
         "value":0.7093054825
      },
      "JPY":{
         "code":"JPY",
         "value":138.0572308513
      },
      "KES":{
         "code":"KES",
         "value":141.3893632301
      },
      "KGS":{
         "code":"KGS",
         "value":87.8705721802
      },
      "KHR":{
         "code":"KHR",
         "value":4127.0097392613
      },
      "KMF":{
         "code":"KMF",
         "value":439.001207548
      },
      "KPW":{
         "code":"KPW",
         "value":899.9766656541
      },
      "KRW":{
         "code":"KRW",
         "value":1267.1829463967
      },
      "KWD":{
         "code":"KWD",
         "value":0.3061909041
      },
      "KYD":{
         "code":"KYD",
         "value":0.8331865814
      },
      "KZT":{
         "code":"KZT",
         "value":444.7645107843
      },
      "LAK":{
         "code":"LAK",
         "value":19130.058439006
      },
      "LBP":{
         "code":"LBP",
         "value":15255.02630148
      },
      "LKR":{
         "code":"LKR",
         "value":317.9500948027
      },
      "LRD":{
         "code":"LRD",
         "value":183.7034464834
      },
      "LSL":{
         "code":"LSL",
         "value":18.0450145363
      },
      "LTC":{
         "code":"LTC",
         "value":0.0098095817
      },
      "LTL":{
         "code":"LTL",
         "value":2.9527489049
      },
      "LVL":{
         "code":"LVL",
         "value":0.6048910606
      },
      "LYD":{
         "code":"LYD",
         "value":4.7549916632
      },
      "MAD":{
         "code":"MAD",
         "value":9.6995217089
      },
      "MATIC":{
         "code":"MATIC",
         "value":1.178784546
      },
      "MDL":{
         "code":"MDL",
         "value":18.0931767702
      },
      "MGA":{
         "code":"MGA",
         "value":4525.0078041453
      },
      "MKD":{
         "code":"MKD",
         "value":54.89029208
      },
      "MMK":{
         "code":"MMK",
         "value":2099.5208100983
      },
      "MNT":{
         "code":"MNT",
         "value":3443.9870816343
      },
      "MOP":{
         "code":"MOP",
         "value":8.0569787014
      },
      "MRO":{
         "code":"MRO",
         "value":357.000866415
      },
      "MUR":{
         "code":"MUR",
         "value":45.3994086676
      },
      "MVR":{
         "code":"MVR",
         "value":15.4096760114
      },
      "MWK":{
         "code":"MWK",
         "value":1050.0010297511
      },
      "MXN":{
         "code":"MXN",
         "value":16.8568508968
      },
      "MYR":{
         "code":"MYR",
         "value":4.5895119248
      },
      "MZN":{
         "code":"MZN",
         "value":63.2502324112
      },
      "NAD":{
         "code":"NAD",
         "value":18.1601352139
      },
      "NGN":{
         "code":"NGN",
         "value":777.5010924989
      },
      "NIO":{
         "code":"NIO",
         "value":36.5250112472
      },
      "NOK":{
         "code":"NOK",
         "value":9.9475767006
      },
      "NPR":{
         "code":"NPR",
         "value":132.4392234557
      },
      "NZD":{
         "code":"NZD",
         "value":1.5646174958
      },
      "OMR":{
         "code":"OMR",
         "value":0.3849952031
      },
      "PAB":{
         "code":"PAB",
         "value":0.999854213
      },
      "PEN":{
         "code":"PEN",
         "value":3.5689754834
      },
      "PGK":{
         "code":"PGK",
         "value":3.5203230446
      },
      "PHP":{
         "code":"PHP",
         "value":54.355087793
      },
      "PKR":{
         "code":"PKR",
         "value":275.7258557455
      },
      "PLN":{
         "code":"PLN",
         "value":3.9604713092
      },
      "PYG":{
         "code":"PYG",
         "value":7267.9699083105
      },
      "QAR":{
         "code":"QAR",
         "value":3.6409923394
      },
      "RON":{
         "code":"RON",
         "value":4.398606172
      },
      "RSD":{
         "code":"RSD",
         "value":104.4401417269
      },
      "RUB":{
         "code":"RUB",
         "value":90.1296206992
      },
      "RWF":{
         "code":"RWF",
         "value":1170.003532371
      },
      "SAR":{
         "code":"SAR",
         "value":3.7518260532
      },
      "SBD":{
         "code":"SBD",
         "value":8.3688012418
      },
      "SCR":{
         "code":"SCR",
         "value":14.011718344
      },
      "SDG":{
         "code":"SDG",
         "value":601.5078815415
      },
      "SEK":{
         "code":"SEK",
         "value":10.2042053054
      },
      "SGD":{
         "code":"SGD",
         "value":1.3225572279
      },
      "SHP":{
         "code":"SHP",
         "value":1.2167521294
      },
      "SLL":{
         "code":"SLL",
         "value":19750.047154849
      },
      "SOL":{
         "code":"SOL",
         "value":0.0385401447
      },
      "SOS":{
         "code":"SOS",
         "value":568.4964594839
      },
      "SRD":{
         "code":"SRD",
         "value":37.5904594664
      },
      "STD":{
         "code":"STD",
         "value":20698.022632306
      },
      "SVC":{
         "code":"SVC",
         "value":8.7481652431
      },
      "SYP":{
         "code":"SYP",
         "value":2512.4978423177
      },
      "SZL":{
         "code":"SZL",
         "value":18.0300105843
      },
      "THB":{
         "code":"THB",
         "value":34.5601589045
      },
      "TJS":{
         "code":"TJS",
         "value":10.9377613397
      },
      "TMT":{
         "code":"TMT",
         "value":3.5000072704
      },
      "TND":{
         "code":"TND",
         "value":3.0350415149
      },
      "TOP":{
         "code":"TOP",
         "value":2.352307027
      },
      "TRY":{
         "code":"TRY",
         "value":26.0626717045
      },
      "TTD":{
         "code":"TTD",
         "value":6.7855879496
      },
      "TWD":{
         "code":"TWD",
         "value":30.8091130672
      },
      "TZS":{
         "code":"TZS",
         "value":2445.0045244722
      },
      "UAH":{
         "code":"UAH",
         "value":36.9197994775
      },
      "UGX":{
         "code":"UGX",
         "value":3669.3031570918
      },
      "USD":{
         "code":"USD",
         "value":1.0000012808
      },
      "UYU":{
         "code":"UYU",
         "value":38.133560322
      },
      "UZS":{
         "code":"UZS",
         "value":11605.034783341
      },
      "VEF":{
         "code":"VEF",
         "value":2836037.181317
      },
      "VND":{
         "code":"VND",
         "value":23675.028193576
      },
      "VUV":{
         "code":"VUV",
         "value":116.7161361276
      },
      "WST":{
         "code":"WST",
         "value":2.6855260129
      },
      "XAF":{
         "code":"XAF",
         "value":587.0508523048
      },
      "XAG":{
         "code":"XAG",
         "value":0.0401916428
      },
      "XAU":{
         "code":"XAU",
         "value":0.000510183
      },
      "XCD":{
         "code":"XCD",
         "value":2.702553075
      },
      "XDR":{
         "code":"XDR",
         "value":0.7448688457
      },
      "XOF":{
         "code":"XOF",
         "value":592.0010277505
      },
      "XPD":{
         "code":"XPD",
         "value":0.0007736349
      },
      "XPF":{
         "code":"XPF",
         "value":106.850146486
      },
      "XPT":{
         "code":"XPT",
         "value":0.001026739
      },
      "XRP":{
         "code":"XRP",
         "value":1.2354673655
      },
      "YER":{
         "code":"YER",
         "value":250.350073683
      },
      "ZAR":{
         "code":"ZAR",
         "value":17.9462790192
      },
      "ZMK":{
         "code":"ZMK",
         "value":9001.2148877064
      },
      "ZMW":{
         "code":"ZMW",
         "value":18.4209625559
      },
      "ZWL":{
         "code":"ZWL",
         "value":322.0005136925
      }
   }
}

The API response comes as a JSON and consists of a meta and a data key. The meta holds useful information like the last_updated_at datetime to let you know when this dataset was last updated. The data key holds the actual currency information.

Benefits of Using Currency Exchange API

Currency exchange APIs provide various benefits to businesses, developers, and organizations operating internationally or dealing with financial transactions. Here are some key advantages:

  1. Accuracy: Currency exchange APIs provide accurate data, often directly from reliable financial market sources. This helps ensure that financial transactions are based on the correct conversion rates.
  2. Real-Time Updates: Currency exchange rates fluctuate continuously due to market conditions. APIs provide real-time or near-real-time exchange rate information, ensuring you always use the most current rates.
  3. Automation: You can automate the process of fetching and updating currency exchange rates. This saves time and reduces errors that might occur in manual updates.
  4. Integration: They can be easily integrated into different platforms, software, and applications, enhancing their functionality. This is particularly beneficial for e-commerce platforms, accounting software, and financial applications that need to handle multi-currency transactions.
  5. Globalization: For businesses with an international customer base, having access to real-time exchange rates enables smooth global operations and enhances user experience by showing prices in local currencies.
  6. Historical Data Access: Some APIs also provide historical exchange rate data, which can be beneficial for financial analysis and forecasting.
  7. Scalability: Your need for currency exchange data may increase as your business grows. APIs often offer the ability to scale up as needed.
  8. Support for Multiple Currencies: Many currency exchange APIs offer data on a wide range of global currencies. This allows businesses to operate in multiple markets without needing to source exchange rate data from multiple places.

In conclusion, currency exchange APIs are a powerful tool for businesses, developers, and organizations that engage in international transactions or require real-time, accurate, and automated exchange rate data. They ensure the most current rates are always used by providing real-time updates.

Prerequisite

To get the API key, we need to register with Currency API. After signing up, it will redirect you to the Dashboard. Perform the steps below to complete the signup process.

Step 1: Enable Multi-Currency

Before your organization can use multiple currencies, the feature must be turned on. To enable multiple currencies in your organization, perform the steps below:

  1. Familiarize yourself with the implications of enabling multiple currencies.
  2. In Setup, enter Company Information in the Quick Find box, then select Company Information and click Edit.
  3. Ensure that your selected currency locale is the default currency that you want to use for current and future records. Enable Activate Multiple Currencies, and then save your changes.

Step 2: Getting the Currency API Key

  1. Visit the Website: Navigate to the URL in your browser.
  2. Sign Up: Look for a Start For Free button (top right corner of the page).
  3. Fill in Your Details: You’ll need to provide some personal information, such as your name and email address.
  4. Choose a Plan: Choose a free plan.
  5. Accept Terms and Conditions: Before completing your registration, you’ll need to accept the site’s terms and conditions or user agreement. Make sure to read this carefully.
  6. Verify Your Email: Currency API will send you a verification email to confirm your address. Go to your email account, open the verification email, and click the verification link.
  7. Get Your API Key: After you’ve confirmed your email, go to your account dashboard on the website to get your API key.


After signing up, you’ll need to refer to the website’s API documentation to use the API. This should include detailed instructions on how to make requests, what data you can retrieve, and other technical details.

Automation Champion Approach (I-do):

While this can be solved using various automation tools like Apex Code and others, we will use Salesforce Flow and the newly introduced HTTP Callout (GET) flow feature.

HTTP Callout pulls or sends data between the Salesforce database and an external system via Flow Builder without using code. You can set up direct integrations as needed without having to work with a developer or call a middleware tool, such as Mulesoft. After you configure the HTTP callout action in a flow, Flow Builder auto-generates an external service registration, an invocable action, and Apex Class that you can use to create an Apex-defined resource for flows. You can then use the data output of the API request as input within Flow Builder and across Salesforce.

You can use HTTP Callout to connect a flow to a variety of APIs.

  • Get address information using a map API
  • Get weather conditions with a weather service API
  • Generate the barcode with a barcode service API
  • Get payment authorization information with a payment processing API
  • and much more

Let’s take a pause here and familiarize yourself with the DatedConversionRate and CurrencyType objects in Salesforce.

Object Name
Details
DatedConversionRate It represents the dated exchange rates used by an organization for which the multicurrency and the effective dated currency features are enabled.
CurrencyType It represents the currencies used by an organization for which the multicurrency feature is enabled.

Before discussing the solution, let me show you a diagram of the process at a high level. Please spend a few minutes going through the following Flow diagram to understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 2 steps to solve Madison’s business requirement using Schedule-Triggered Flow. We must:

  1. Create a Named Credential
  2. Salesforce Flow
    1. Define flow properties for scheduled-triggered flow
    2. Add a pause element to make callout possible from schedule triggered-flow
    3. Configure an HTTP GET callout for Currency API
    4. Using Decision Element to Check the Currency API Callout Response Code
    5. Add a Get Records element to find the Active Currencies
    6. Add a Decision element to check if the active currency was found or not (from step 5)
    7. Add a loop element to retrieve records from the record collection variable (from step 5)
    8. Create three formulas to find the exchange rates for a given currency IsoCode
    9. Add an assignment element to Assign the values to a record variable
    10. Add an assignment element to add the record variable to a record collection variable
    11. Add a create records element to insert data from the record collection variable

Step 1: Create a Named Credential

  1. Click Setup.
  2. In the Quick Find box, enter Named Credentials, and then select Named Credentials.
  3. Click New Legacy.
  4. Fill out the page with the callout endpoint’s URL and authentication parameters.
  5. Click Save.

Step 2.1: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Schedule-Triggered Flow option, click on Create, and configure the flow as follows:
    1. Set Schedule
      1. Start Date: July 14, 2023
      2. Start Time: 12:53 AM
      3. Frequency: Daily
  5. Click Done.

Step 2.2: Adding a Pause Element to Enable Callouts in a Schedule-Triggered Flow

A schedule-triggered flow can make callouts only after executing a Pause element. For example, without a Pause element, the flow can’t access external objects, execute Apex actions that make callouts, or execute actions that are generated from External Services registrations.

  1. Click the + icon, and select the Pause element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under PAUSE CONFIGURATION, enter the Label the API Name will auto-populate.
    1. PAUSE CONDITIONS
      1. When to Pause: Always Pause Flow – No Conditions
    2. RESUME CONDITIONS
      1. Pause Until: A Specified Time
      2. Time Source: Specified time
      3. Define Resume Time
        1. Base Time: {!$Flow.CurrentDateTime}
        2. Offset Number: 0
        3. Offset Unit (Hours or Days): Hours
  4. Click Done.

Step 2.3: Configure an HTTP GET Callout Action

HTTP Callout guides you through entering the details about the HTTP web-based service or REST API endpoint you’re connecting to. After you complete the configuration, you invoke the action in a flow.

  1. Click the + icon, and select Action.
  2. Click + Create HTTP Callout.
  3. Configure the external service that connects Salesforce to the HTTP-based API.
    1. Enter a Name for the external service.
    2. Select the named credential that you created in Step 1.
    3. Click Next.
  4. The next step is configuring the invocable action that you can use in Flow Builder or across Salesforce.
    1. For Label, enter the action that the callout performs.
    2. Method: GET
    3. Add the URL endpoint for the request.
      1. URL Path: /v3/latest
    4. Add query parameter keys if the API you’re calling has them. When you use this action in a flow, you input values for the defined keys.
      1. Click Add Key
        1. Key: base_currency
        2. Data Type: String
        3. Required: True
      2. Click Add Key
        1. Key: apikey
        2. Data Type: String
        3. Required: True
  5. Provide a sample API response body. Salesforce generates a data structure from the sample response.
    1. Navigate to Provide Sample Response section.
    2. Click New.
    3. Paste a sample JSON response.
    4. Click Review and confirm that the Apex data structure is correct.
    5. To make changes, edit the text in Sample JSON Response or select data types from the data structure.
    6. Click Review.
    7. Click Done.
  6. Click Save.
  7. Flow Builder creates the action and external service. The action is available in the Actions window in the flow.
  8. The next step is to add the apex action generated by the HTTP Callout setup in the previous steps. We will use the Action element.
    1. Label the new action CurrencyAPi Callout.
    2. Set Input Values

      1. apikey: YOUR_API_KEY
      2. base_currency: USD
  9. Click Done.

Step 2.4: Using Decision Element to Check the Currency API Callout Response Code

Now we will use the Decision element to check the Currency API response code. If the callout is successful, we will take the next step. Otherwise, no further action is required.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!CurrencyAPI_Callout.responseCode}
      2. Operator: Equals
      3. Value: 200
  5. Click Done.

Step 2.5: Adding a Get Record Element to Find Active Currencies

We will use the Get Records element to find the Active Currencies excluding corporate currency.

  1. On Flow Designer, below the Succesful node, click on the +icon and select the Get Recordselement.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the CurrencyType object from the dropdown list.
  4. Select All Conditions Are Met (AND).
  5. Set Filter Conditions
    1. Row 1:
      1. Field: IsActive
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
    2. Click Add Condition
    3. Row 2:
      1. Field: IsCorporate
      2. Operator: Equals
      3. Value: {!$GlobalConstant.False}
  6. How Many Records to Store:
    1. Select All records
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields.
  8. Click Done.

Step 2.6: Using Decision Element to Check if the Active Currency Was Found or Not (from Step 2.5)

Now we will use the Decision element to check if the previous get record element returns a user record or not. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Active_Currency}
      2. Operator: Is Null
      3. Value: {!$GlobalConstant.False}
  5. Click Done.

Step 2.7: Add a Loop Element to Retrieve Records from Record Collection Variable (from Step 2.5) 

  1. On Flow Designer, below the Yes node, click on the +icon and select the Loop element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For Collection Variable, select {!{!Active_Currency}.
  4. For Specify Direction for Iterating Over Collection, select First item to last item.
  5. Click Done.

Step 2.8: Formula to Determine the Latest Exchange Rate for a Given Currency IsoCode

To tackle the limitation of the 3900-character limit in the flow formula, I devised a solution by using three formulas using an If-Else statement. An alternative approach to overcome this challenge is to utilize an Apex Class.

  1. Under Toolbox, select Manager, then click New Resource to determine whether the record is created or updated. 
  2. Input the following information:
    1. Resource Type: Formula
    2. API Name: forT_CurrencyExchangeRate1
    3. Data Type: Number
    4. Decimal Places: 4
    5. Formula:
      
      
      If(ISPICKVAL({!Loop.IsoCode}, "ZAR"), {!CurrencyAPI_Callout.2XX.data.ZAR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "ETB"), {!CurrencyAPI_Callout.2XX.data.ETB.value},
      If(ISPICKVAL({!Loop.IsoCode}, "AED"), {!CurrencyAPI_Callout.2XX.data.AED.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BHD"), {!CurrencyAPI_Callout.2XX.data.BHD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "DZD"), {!CurrencyAPI_Callout.2XX.data.DZD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "EGP"), {!CurrencyAPI_Callout.2XX.data.EGP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "IQD"), {!CurrencyAPI_Callout.2XX.data.IQD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "JOD"), {!CurrencyAPI_Callout.2XX.data.JOD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "KWD"), {!CurrencyAPI_Callout.2XX.data.KWD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "LBP"), {!CurrencyAPI_Callout.2XX.data.LBP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "LYD"), {!CurrencyAPI_Callout.2XX.data.LYD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "MAD"), {!CurrencyAPI_Callout.2XX.data.MAD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "OMR"), {!CurrencyAPI_Callout.2XX.data.OMR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "QAR"), {!CurrencyAPI_Callout.2XX.data.QAR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "SAR"), {!CurrencyAPI_Callout.2XX.data.SAR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "SDG"), {!CurrencyAPI_Callout.2XX.data.SDG.value},
      If(ISPICKVAL({!Loop.IsoCode}, "SYP"), {!CurrencyAPI_Callout.2XX.data.SYP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "TND"), {!CurrencyAPI_Callout.2XX.data.TND.value},
      If(ISPICKVAL({!Loop.IsoCode}, "YER"), {!CurrencyAPI_Callout.2XX.data.YER.value},
      If(ISPICKVAL({!Loop.IsoCode}, "AZN"), {!CurrencyAPI_Callout.2XX.data.AZN.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BYN"), {!CurrencyAPI_Callout.2XX.data.BYN.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BGN"), {!CurrencyAPI_Callout.2XX.data.BGN.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BDT"), {!CurrencyAPI_Callout.2XX.data.BDT.value},
      If(ISPICKVAL({!Loop.IsoCode}, "INR"), {!CurrencyAPI_Callout.2XX.data.INR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BAM"), {!CurrencyAPI_Callout.2XX.data.BAM.value},
      If(ISPICKVAL({!Loop.IsoCode}, "EUR"), {!CurrencyAPI_Callout.2XX.data.EUR.value},
      If(ISPICKVAL({!Loop.IsoCode}, "CZK"), {!CurrencyAPI_Callout.2XX.data.CZK.value},
      If(ISPICKVAL({!Loop.IsoCode}, "GBP"), {!CurrencyAPI_Callout.2XX.data.GBP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "DKK"), {!CurrencyAPI_Callout.2XX.data.DKK.value},
      If(ISPICKVAL({!Loop.IsoCode}, "CHF"), {!CurrencyAPI_Callout.2XX.data.CHF.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BTN"), {!CurrencyAPI_Callout.2XX.data.BTN.value},
      If(ISPICKVAL({!Loop.IsoCode}, "XCD"), {!CurrencyAPI_Callout.2XX.data.XCD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "AUD"), {!CurrencyAPI_Callout.2XX.data.AUD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BBD"), {!CurrencyAPI_Callout.2XX.data.BBD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BMD"), {!CurrencyAPI_Callout.2XX.data.BMD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BSD"), {!CurrencyAPI_Callout.2XX.data.BSD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BWP"), {!CurrencyAPI_Callout.2XX.data.BWP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "BZD"), {!CurrencyAPI_Callout.2XX.data.BZD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "CAD"), {!CurrencyAPI_Callout.2XX.data.CAD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "XAF"), {!CurrencyAPI_Callout.2XX.data.XAF.value},
      If(ISPICKVAL({!Loop.IsoCode}, "ERN"), {!CurrencyAPI_Callout.2XX.data.ERN.value},
      If(ISPICKVAL({!Loop.IsoCode}, "FJD"), {!CurrencyAPI_Callout.2XX.data.FJD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "FKP"), {!CurrencyAPI_Callout.2XX.data.FKP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "GHS"), {!CurrencyAPI_Callout.2XX.data.GHS.value},
      If(ISPICKVAL({!Loop.IsoCode}, "GIP"), {!CurrencyAPI_Callout.2XX.data.GIP.value},
      If(ISPICKVAL({!Loop.IsoCode}, "GMD"), {!CurrencyAPI_Callout.2XX.data.GMD.value},
      If(ISPICKVAL({!Loop.IsoCode}, "GYD"), {!CurrencyAPI_Callout.2XX.data.GYD.value},
      {!forT_CurrencyExchangeRate2})))))))))))))))))))))))))))))))))))))))))))))))


  3. Click Done.

You can follow the same steps to incorporate two additional formulas to further expand on the aforementioned process. By repeating the above-mentioned steps, you can create two more formulas in a similar manner.

forT_CurrencyExchangeRate2


If(ISPICKVAL({!Loop.IsoCode}, "KES"), {!CurrencyAPI_Callout.2XX.data.KES.value},
If(ISPICKVAL({!Loop.IsoCode}, "KYD"), {!CurrencyAPI_Callout.2XX.data.KYD.value},
If(ISPICKVAL({!Loop.IsoCode}, "LRD"), {!CurrencyAPI_Callout.2XX.data.LRD.value},
If(ISPICKVAL({!Loop.IsoCode}, "MGA"), {!CurrencyAPI_Callout.2XX.data.MGA.value},
If(ISPICKVAL({!Loop.IsoCode}, "MUR"), {!CurrencyAPI_Callout.2XX.data.MUR.value},
If(ISPICKVAL({!Loop.IsoCode}, "MWK"), {!CurrencyAPI_Callout.2XX.data.MWK.value},
If(ISPICKVAL({!Loop.IsoCode}, "MYR"), {!CurrencyAPI_Callout.2XX.data.MYR.value},
If(ISPICKVAL({!Loop.IsoCode}, "NAD"), {!CurrencyAPI_Callout.2XX.data.NAD.value},
If(ISPICKVAL({!Loop.IsoCode}, "NGN"), {!CurrencyAPI_Callout.2XX.data.NGN.value},
If(ISPICKVAL({!Loop.IsoCode}, "NZD"), {!CurrencyAPI_Callout.2XX.data.NZD.value},
If(ISPICKVAL({!Loop.IsoCode}, "PGK"), {!CurrencyAPI_Callout.2XX.data.PGK.value},
If(ISPICKVAL({!Loop.IsoCode}, "PHP"), {!CurrencyAPI_Callout.2XX.data.PHP.value},
If(ISPICKVAL({!Loop.IsoCode}, "PKR"), {!CurrencyAPI_Callout.2XX.data.PKR.value},
If(ISPICKVAL({!Loop.IsoCode}, "RWF"), {!CurrencyAPI_Callout.2XX.data.RWF.value},
If(ISPICKVAL({!Loop.IsoCode}, "SBD"), {!CurrencyAPI_Callout.2XX.data.SBD.value},
If(ISPICKVAL({!Loop.IsoCode}, "SCR"), {!CurrencyAPI_Callout.2XX.data.SCR.value},
If(ISPICKVAL({!Loop.IsoCode}, "SGD"), {!CurrencyAPI_Callout.2XX.data.SGD.value},
If(ISPICKVAL({!Loop.IsoCode}, "SHP"), {!CurrencyAPI_Callout.2XX.data.SHP.value},
If(ISPICKVAL({!Loop.IsoCode}, "SLL"), {!CurrencyAPI_Callout.2XX.data.SLL.value},
If(ISPICKVAL({!Loop.IsoCode}, "ANG"), {!CurrencyAPI_Callout.2XX.data.ANG.value},
If(ISPICKVAL({!Loop.IsoCode}, "SZL"), {!CurrencyAPI_Callout.2XX.data.SZL.value},
If(ISPICKVAL({!Loop.IsoCode}, "TOP"), {!CurrencyAPI_Callout.2XX.data.TOP.value},
If(ISPICKVAL({!Loop.IsoCode}, "TTD"), {!CurrencyAPI_Callout.2XX.data.TTD.value},
If(ISPICKVAL({!Loop.IsoCode}, "TZS"), {!CurrencyAPI_Callout.2XX.data.TZS.value},
If(ISPICKVAL({!Loop.IsoCode}, "UGX"), {!CurrencyAPI_Callout.2XX.data.UGX.value},
If(ISPICKVAL({!Loop.IsoCode}, "USD"), {!CurrencyAPI_Callout.2XX.data.USD.value},
If(ISPICKVAL({!Loop.IsoCode}, "VUV"), {!CurrencyAPI_Callout.2XX.data.VUV.value},
If(ISPICKVAL({!Loop.IsoCode}, "WST"), {!CurrencyAPI_Callout.2XX.data.WST.value},
If(ISPICKVAL({!Loop.IsoCode}, "ARS"), {!CurrencyAPI_Callout.2XX.data.ARS.value},
If(ISPICKVAL({!Loop.IsoCode}, "BOB"), {!CurrencyAPI_Callout.2XX.data.BOB.value},
If(ISPICKVAL({!Loop.IsoCode}, "CLP"), {!CurrencyAPI_Callout.2XX.data.CLP.value},
If(ISPICKVAL({!Loop.IsoCode}, "COP"), {!CurrencyAPI_Callout.2XX.data.COP.value},
If(ISPICKVAL({!Loop.IsoCode}, "CRC"), {!CurrencyAPI_Callout.2XX.data.CRC.value},
If(ISPICKVAL({!Loop.IsoCode}, "CUP"), {!CurrencyAPI_Callout.2XX.data.CUP.value},
If(ISPICKVAL({!Loop.IsoCode}, "DOP"), {!CurrencyAPI_Callout.2XX.data.DOP.value},
If(ISPICKVAL({!Loop.IsoCode}, "GTQ"), {!CurrencyAPI_Callout.2XX.data.GTQ.value},
If(ISPICKVAL({!Loop.IsoCode}, "HNL"), {!CurrencyAPI_Callout.2XX.data.HNL.value},
If(ISPICKVAL({!Loop.IsoCode}, "MXN"), {!CurrencyAPI_Callout.2XX.data.MXN.value},
If(ISPICKVAL({!Loop.IsoCode}, "NIO"), {!CurrencyAPI_Callout.2XX.data.NIO.value},
If(ISPICKVAL({!Loop.IsoCode}, "PAB"), {!CurrencyAPI_Callout.2XX.data.PAB.value},
If(ISPICKVAL({!Loop.IsoCode}, "PEN"), {!CurrencyAPI_Callout.2XX.data.PEN.value},
If(ISPICKVAL({!Loop.IsoCode}, "PYG"), {!CurrencyAPI_Callout.2XX.data.PYG.value},
If(ISPICKVAL({!Loop.IsoCode}, "UYU"), {!CurrencyAPI_Callout.2XX.data.UYU.value},
If(ISPICKVAL({!Loop.IsoCode}, "IRR"), {!CurrencyAPI_Callout.2XX.data.IRR.value},
If(ISPICKVAL({!Loop.IsoCode}, "GNF"), {!CurrencyAPI_Callout.2XX.data.GNF.value},
If(ISPICKVAL({!Loop.IsoCode}, "HTG"), {!CurrencyAPI_Callout.2XX.data.HTG.value},
If(ISPICKVAL({!Loop.IsoCode}, "KMF"), {!CurrencyAPI_Callout.2XX.data.KMF.value},
If(ISPICKVAL({!Loop.IsoCode}, "XPF"), {!CurrencyAPI_Callout.2XX.data.XPF.value},
If(ISPICKVAL({!Loop.IsoCode}, "HRK"), {!CurrencyAPI_Callout.2XX.data.HRK.value}, {!forT_CurrencyExchangeRate3})))))))))))))))))))))))))))))))))))))))))))))))))

forT_CurrencyExchangeRate3


If(ISPICKVAL({!Loop.IsoCode}, "HUF"), {!CurrencyAPI_Callout.2XX.data.HUF.value},
If(ISPICKVAL({!Loop.IsoCode}, "AMD"), {!CurrencyAPI_Callout.2XX.data.AMD.value},
If(ISPICKVAL({!Loop.IsoCode}, "ISK"), {!CurrencyAPI_Callout.2XX.data.ISK.value},
If(ISPICKVAL({!Loop.IsoCode}, "JPY"), {!CurrencyAPI_Callout.2XX.data.JPY.value},
If(ISPICKVAL({!Loop.IsoCode}, "GEL"), {!CurrencyAPI_Callout.2XX.data.GEL.value},
If(ISPICKVAL({!Loop.IsoCode}, "KZT"), {!CurrencyAPI_Callout.2XX.data.KZT.value},
If(ISPICKVAL({!Loop.IsoCode}, "KHR"), {!CurrencyAPI_Callout.2XX.data.KHR.value},
If(ISPICKVAL({!Loop.IsoCode}, "KPW"), {!CurrencyAPI_Callout.2XX.data.KPW.value},
If(ISPICKVAL({!Loop.IsoCode}, "KRW"), {!CurrencyAPI_Callout.2XX.data.KRW.value},
If(ISPICKVAL({!Loop.IsoCode}, "KGS"), {!CurrencyAPI_Callout.2XX.data.KGS.value},
If(ISPICKVAL({!Loop.IsoCode}, "LAK"), {!CurrencyAPI_Callout.2XX.data.LAK.value},
If(ISPICKVAL({!Loop.IsoCode}, "CDF"), {!CurrencyAPI_Callout.2XX.data.CDF.value},
If(ISPICKVAL({!Loop.IsoCode}, "MKD"), {!CurrencyAPI_Callout.2XX.data.MKD.value},
If(ISPICKVAL({!Loop.IsoCode}, "BND"), {!CurrencyAPI_Callout.2XX.data.BND.value},
If(ISPICKVAL({!Loop.IsoCode}, "MMK"), {!CurrencyAPI_Callout.2XX.data.MMK.value},
If(ISPICKVAL({!Loop.IsoCode}, "NPR"), {!CurrencyAPI_Callout.2XX.data.NPR.value},
If(ISPICKVAL({!Loop.IsoCode}, "AWG"), {!CurrencyAPI_Callout.2XX.data.AWG.value},
If(ISPICKVAL({!Loop.IsoCode}, "SRD"), {!CurrencyAPI_Callout.2XX.data.SRD.value},
If(ISPICKVAL({!Loop.IsoCode}, "NOK"), {!CurrencyAPI_Callout.2XX.data.NOK.value},
If(ISPICKVAL({!Loop.IsoCode}, "PLN"), {!CurrencyAPI_Callout.2XX.data.PLN.value},
If(ISPICKVAL({!Loop.IsoCode}, "AFN"), {!CurrencyAPI_Callout.2XX.data.AFN.value},
If(ISPICKVAL({!Loop.IsoCode}, "AOA"), {!CurrencyAPI_Callout.2XX.data.AOA.value},
If(ISPICKVAL({!Loop.IsoCode}, "BRL"), {!CurrencyAPI_Callout.2XX.data.BRL.value},
If(ISPICKVAL({!Loop.IsoCode}, "CVE"), {!CurrencyAPI_Callout.2XX.data.CVE.value},
If(ISPICKVAL({!Loop.IsoCode}, "MZN"), {!CurrencyAPI_Callout.2XX.data.MZN.value},
If(ISPICKVAL({!Loop.IsoCode}, "BIF"), {!CurrencyAPI_Callout.2XX.data.BIF.value},
If(ISPICKVAL({!Loop.IsoCode}, "MDL"), {!CurrencyAPI_Callout.2XX.data.MDL.value},
If(ISPICKVAL({!Loop.IsoCode}, "RON"), {!CurrencyAPI_Callout.2XX.data.RON.value},
If(ISPICKVAL({!Loop.IsoCode}, "RUB"), {!CurrencyAPI_Callout.2XX.data.RUB.value},
If(ISPICKVAL({!Loop.IsoCode}, "UAH"), {!CurrencyAPI_Callout.2XX.data.UAH.value},
If(ISPICKVAL({!Loop.IsoCode}, "DJF"), {!CurrencyAPI_Callout.2XX.data.DJF.value},
If(ISPICKVAL({!Loop.IsoCode}, "SOS"), {!CurrencyAPI_Callout.2XX.data.SOS.value},
If(ISPICKVAL({!Loop.IsoCode}, "ALL"), {!CurrencyAPI_Callout.2XX.data.ALL.value},
If(ISPICKVAL({!Loop.IsoCode}, "RSD"), {!CurrencyAPI_Callout.2XX.data.RSD.value},
If(ISPICKVAL({!Loop.IsoCode}, "SEK"), {!CurrencyAPI_Callout.2XX.data.SEK.value},
If(ISPICKVAL({!Loop.IsoCode}, "LKR"), {!CurrencyAPI_Callout.2XX.data.LKR.value},
If(ISPICKVAL({!Loop.IsoCode}, "TJS"), {!CurrencyAPI_Callout.2XX.data.TJS.value},
If(ISPICKVAL({!Loop.IsoCode}, "THB"), {!CurrencyAPI_Callout.2XX.data.THB.value},
If(ISPICKVAL({!Loop.IsoCode}, "UZS"), {!CurrencyAPI_Callout.2XX.data.UZS.value},
If(ISPICKVAL({!Loop.IsoCode}, "VND"), {!CurrencyAPI_Callout.2XX.data.VND.value},
If(ISPICKVAL({!Loop.IsoCode}, "XOF"), {!CurrencyAPI_Callout.2XX.data.XOF.value},
If(ISPICKVAL({!Loop.IsoCode}, "CNY"), {!CurrencyAPI_Callout.2XX.data.CNY.value},
If(ISPICKVAL({!Loop.IsoCode}, "IDR"), {!CurrencyAPI_Callout.2XX.data.IDR.value},
If(ISPICKVAL({!Loop.IsoCode}, "ILS"), {!CurrencyAPI_Callout.2XX.data.ILS.value},
If(ISPICKVAL({!Loop.IsoCode}, "JMD"), {!CurrencyAPI_Callout.2XX.data.JMD.value}, 
If(ISPICKVAL({!Loop.IsoCode}, "HKD"), {!CurrencyAPI_Callout.2XX.data.HKD.value},
If(ISPICKVAL({!Loop.IsoCode}, "TWD"), {!CurrencyAPI_Callout.2XX.data.TWD.value}, 0.0000)))))))))))))))))))))))))))))))))))))))))))))))

Step 2.9: Adding an Assignment Element to Assign the Values to a Record Variable

The next step is to add value to the Dated Conversion Rate record variable to insert the latest exchange rate for active currencies Isocode. For this, we will use Assignment element. 

  1. Create a Record Variable varR_DatedConversionRate type DatedConversionRate.
  2. On Flow Designer, click on the +icon and select the Assignment element.
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varR_DatedConversionRate.StartDate}
      2. Operator: Equals
      3. Value: {!$Flow.CurrentDate}
    2. Add Assignment 
    3. Row 2:
      1. Field: {!varR_DatedConversionRate.IsoCode}
      2. Operator: Equals
      3. Value: {!Loop.IsoCode}
    4. Add Assignment 
    5. Row 3:
      1. Field: {!varR_DatedConversionRate.ConversionRate}
      2. Operator: Equals
      3. Value: {!forT_CurrencyExchangeRate1}
  5. Click Done.

Step 2.10: Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. Create a Record Collection Variable varR_DatedConversionRates type DatedConversionRates to store the record variable (created in step 2.9) for the bulk process.
  2. On Flow Designer, click on the +icon and select the Assignment element.
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {varR_DatedConversionRates}
      2. Operator: Add
      3. Value: {varR_DatedConversionRate}
  5. Click Done.

Step 2.11: Adding a Create Records Element to Update Dated Conversion Rate for Active Currencies

The final task is to insert data into the DatedConversionRates object. For this, we will use the Create Records element.

  1. On Flow Designer, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How Many Records to Create select Multiple.
  4. Map Record Collection: {!varR_DatedConversionRates}
  5. Click Done.

In the end, Madison’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below:

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 58
  5. Interview Label: Scheduled Flow: Latest Exchange Rates
  6. Click Save.

Almost there! Once everything looks good, click the Activate button.

👉 Check out the video for step-by-step instructions.

Monitor Your Schedule Flow

To monitor Flows that are scheduled, navigate to the following path:

  1. Navigate to Setup | Environments | Jobs | Scheduled Jobs.
  2. Now look for your Scheduled Flow displaying information as shown in the following screenshot:
  3. Use the Del link to delete the Scheduled Flow job from the queue.

Proof of Concept

Every night at 12:53 AM, a scheduled job will run to retrieve the latest exchange rates and update DatedConversionRate for active currencies.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Preferred Timing(required)

12 thoughts on “Automate Currency Exchange Rate Updates in Salesforce using Currency Exchange API

  1. Hi Rakesh,

    Great post! But I have a question; I am trying to create a “Formula to Determine the Latest Exchange Rate for a Given Currency IsoCode,” but I am getting an error message when copying to code: The “Loop” resource doesn’t exist in this flow.

    But I see the loop resource on my flow. Is there a reason I’m getting this error?

    1. Rakesh Gupta – Mumbai – 9x Salesforce MVP | Senior Solution Architect | 8x Author | 5x Dreamforce Speaker | Salesforce Coach | Co-host of AutomationHour.com and AppXchangeHour.Com

      Please let me know if you still need help resolving the formula error.

    1. Rakesh Gupta – Mumbai – 9x Salesforce MVP | Senior Solution Architect | 8x Author | 5x Dreamforce Speaker | Salesforce Coach | Co-host of AutomationHour.com and AppXchangeHour.Com

      Feel free to use new named credentials. I used the legacy ones to keep my article focused on HTTPS callouts and currency updates in Salesforce.

  2. Hey Rakesh,

    I’m also looking for this to update ‘currencyTypes’ so that the formula fields are always using “todays” rate. I’ve photocopied the last steps (collection variable / insert currencyTypes etc) but it’s throwing an exception error saying that the values must have between 0 -> decimal places (which they do based on the debug) .. Any thoughts? Or am I missing something here as the latest dated value doesn’t seem to apply when fetching currency values from the API .. they still reference the ‘static’ rates (which are not updted)

    1. Sure, I can assist you with this issue. To better understand and help you resolve the exception error you’re encountering with the ‘currencyTypes’ update, I’ll need to see the debug log and the setup of your flow. Could you please send me the debug log and a screenshot of your flow setup? This will allow me to analyze the exact point of failure and the context in which the error is occurring.

  3. Hello Rakesh, the final create records does not show the Var Collection Variable in the selection. I get the option to add “currency from active currency” not “varR_datedConversionRates. everything else works fine. What Have I done wrong.

    1. Please let me know if you still need help.

  4. Hello Rakesh, the collection variable is not available. We need to create one before adding that to collection Variable in loop right? what was the return type selected?

    1. No, please check Step 2.5

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%