Notes
In Salesforce, dealing with multiple currencies requires careful handling, especially when you need to calculate or display exchange rates. Apex provides powerful tools to manage currency conversions dynamically within your applications. In this article, we'll walk through an example of how to evaluate a currency exchange rate for a specific account using an Apex formula.
FormulaEval.FormulaInstance likelyBuyer = Formula.builder()
.withReturnType(FormulaEval.FormulaReturnType.DECIMAL)
.withType(Account.SObjectType)
.withFormula('ROUND(CURRENCYRATE(TEXT(CURRENCYISOCODE)),2)')
.build();
Account acc = new Account(CURRENCYISOCODE = 'EUR');
Decimal currRate = (Decimal)likelyBuyer.evaluate(acc);
System.debug(currRate);