If you have a multi-currency organization, we use the dated conversion rates in Salesforce (or the corporate rate if not found).


In a dual currency scenario (e.g. Corporate Currency: USD, Customer Currency: EUR, Expense Currency: CAD), we calculate cross rates based on the Salesforce dated conversion rates.  This method is not accurate.


If you maintain your own conversion rates, we can integrate with your environment.


Create a class called " CurrencyRate" implementing Callable with a method called " getRate":

  public class CurrencyConvert implements Callable {
    
    /**
     * Interface implementation
     * @return rate
     */
    public Object call(String action, Map<String, Object> args) {
      if (action == 'getRate') {
        return getRate(
            (String)args.get('fromIso'), 
            (String)args.get('toIso'),
            (Date)args.get('date'));
      }
      return null;
    } // call

    /**
     * Return the rate
     * @param fromIso from
     * @param toIso to
     * @param dd date
     * @return rate or null if not found
     */
    public Decimal getRate(String fromIso, String toIso, Date dd) {
      return null; // your implementation here
    }
  } // CurrencyConvert


We call this class before we use the dated conversion rates and use the value you returned - unless you return zero.

The class will not be called if it is the same currency (fromIso == toIso).


You can test this class by calling the methods in the utility class UtilCurrency we are using for all conversions:


global static Decimal crossConvertFrom (String fromIso, String toIso, Date dd, Decimal amt).
// e.g.
System.assertEquals(123, accorto.UtilCurrency.crossConvertFrom('EUR', 'USD', System.today(), 100));

global static Decimal getCrossRate(String fromIso, String toIso, Date dd);
// e.g.
System.assertEquals(1.23, accorto.UtilCurrency.crossConvertRate('EUR', 'USD', System.today()));

// From currency to corporate currency
global static Decimal getRate (String iso, Date dd);
global static Decimal convertFrom (String iso, Date dd, Decimal amt);