2

I need to convert the Currency from EURO to USD , I am using the fields are

  1. TestCurrency__c - Currency
  2. CurrencyConvert - Formulafield(Currency datatype)

My Organization Corporate Currency is "EURO".

Here i enter the TestCurrency data as Euro then the CurrencyConvert field should be changed as USD with current exchange rates. Is this possible to implement in formula field? How the Conversion will happens using formula fields or triggers ?

3

As far as I know you can't do that using a formula field.

In Salesforce you assign the CurrencyISOCode (this field is visible when you enabled Multi-currency in your Org) and the amount (any currency field). Then Salesforce will show you the converted amount depending of the user's default currency, in reports and layouts.

enter image description here enter image description here

I don't think that you can force any conversion by formula but maybe you can achieve that using some Apex by querying CurrencyType.

More info about currencies in SFDC official doc

2

I once wrote a utility method within a Util.cls that would convert an amount in currency X to the org currency using the appropriate DatedCOnversionRate. This would be invoked by a trigger on the object in question containing the currency amount that needs the org currency value. The trigger would use this method and save the result in a separate custom field like Amount_USD__c if USD was the org currency.

Adapt as needed for your use case

// Singleton, remember when first referenced, key = DatedConversionRate.id
private static Map<ID,DatedConversionRate>              dcrIdToDcrMap;                      

//  ----------------------------------------
//  convertToOrgCurrency - convert value in some ISO currency to org currency as of given date
//  ----------------------------------------
public static Decimal convertToOrgCurrency(String currencyIso, Decimal currencyVal, Date currencyDate) {
    Decimal res;
    if (currencyIso == null || currencyVal == null) {}
    else {
        if (dcrIdToDcrMap == null)              // build the map only once for life of the transaoction
            dcrIdToDcrMap = new Map<ID,DatedConversionRate> ([select id, isoCode, conversionrate, nextStartDate, startDate from DatedConversionRate]);
        for (DatedConversionRate dcr: dcrIdToDcrMap.values()) {
            if (dcr.isoCode != currencyIso)                                         continue;   // look for a match in table against input currency
            if (currencyDate < dcr.startDate || currencyDate >= dcr.nextStartDate)  continue;   // not in the range of effective dates
            System.debug(LoggingLevel.INFO,'Converting using dcr: ' + dcr);
            res =  currencyVal / dcr.conversionRate;
            break;  
        }
    }
    System.debug(LoggingLevel.INFO,'convertToOrgCurrency res= ' + res);
    return res;
}

//  ----------------------------------------
//  convertFromOrgCurrency - convert value in org currency to some iso currency as of given date 
//  ----------------------------------------
public static Decimal convertFromOrgCurrency(String currencyIso, Decimal currencyVal, Date currencyDate) {
    Decimal res;
    if (currencyIso == null || currencyVal == null) {}
    else {
        if (dcrIdToDcrMap == null)              // build the map only once for life of the transaoction
            dcrIdToDcrMap = new Map<ID,DatedConversionRate> ([select id, isoCode, conversionrate, nextStartDate, startDate from DatedConversionRate]);
        for (DatedConversionRate dcr: dcrIdToDcrMap.values()) {
            if (dcr.isoCode != currencyIso)                                         continue;   // look for a match in table against input currency
            if (currencyDate < dcr.startDate || currencyDate >= dcr.nextStartDate)  continue;   // not in the range of effective dates
            System.debug(LoggingLevel.INFO,'Converting using dcr: ' + dcr);
            res =  currencyVal * dcr.conversionRate;
            break;  
        }
    }
    System.debug(LoggingLevel.INFO,'convertFromOrgCurrency res= ' + res);
    return res;
}
  • Thanks for your comment @crop1645, here my organisation currency is "EURO". I need to convert the EURO to USD with current exchange rates. – Venkatsforce Dec 2 '14 at 4:10
  • added the reverse case; Martin is correct that formulas can't use dated exchange rates – cropredy Dec 2 '14 at 18:05

protected by Community May 25 '18 at 12:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.