11

I'm looking for a way to get the Default currency symbol (in a none-multi-currency org) of the salesforce org locale (to have it displayed on a visualforce page in a field that can't be <apex:inputField> or <apex:outputField>) preferably query-able from apex (via the database, a describe or whatever) and then again the actual symbol, meaning € for Euro, $ for dollar, and so on...

There must surely be some sort of mapping hidden in the code somewhere salesforce does this via the input/outputfields if bound to an sobject of type currency

Can anyone point me in the right direction?

3 Answers 3

10

We ended up fixing it this way, this hasn't been tested on a multicurrency org but this works on a singlecurrency org.

    public static String getCurrencyIsoCode(SObject someObject){
        String currencyIso = UserInfo.isMultiCurrencyOrganization() ? (String) someObject.get('CurrencyIsoCode') : UserInfo.getDefaultCurrency();
        return currencyIso;
    }

    public static String getCurrencySymbol(SObject someObject) {
        return getCurrencySymbolFromIso(getCurrencyIsoCode(someObject));
    }

    public static String getCurrencySymbolFromIso(String Iso) {
         String currencySymbol = 
           ('USD' == Iso ? '$' : 
           ('CAD' == Iso ? '$' : 
           ('EUR' == Iso ? '€' : 
           ('GBP' == Iso ? '£' : 
           ('JPY' == Iso ? '¥' : 
           ('KRW' == Iso ? '₩' : 
           ('CNY' == Iso ? '元' : 
           Iso)))))));
           return currencySymbol;
    }
0

SELECT DefaultLocaleSidKey FROM Organization

returns "de_DE_EURO" or "en_GB" for me, so still some way towards getting "EUR" out of it.

No idea if there's better way but if not -> you could play with string.split() or use Eclipse to learn all picklist values and write some mapping code?


To get the €,$ etc. use tricks from https://stackoverflow.com/questions/3888991/currency-code-to-currency-symbol-mapping

VF:

<apex:outputText value="{0, number, ¤ #}">
    <apex:param value="{!Opportunity.Amount}" /><!-- gives me "$ 50000" -->
</apex:outputText>

In Apex - tricky. You could experiment with String.format() but it expects an array of strings so that's where you'd lose the "currency-ness" of your number.

4
  • I was actually hoping of getting the € somehow :)
    – pjcarly
    Nov 15, 2012 at 15:51
  • Tricks from Java code do not help in Salesforce. If we tried to use Java solution like "Currency.getInstance('EUR').getSymbol()" it would say: "Variable does not exist: Currency".
    – Patlatus
    May 30, 2014 at 9:02
  • @Patlatus that's true, I've meant here the ¤ symbol that (when used in Visualforce) does produce something. Check en.wikipedia.org/wiki/Currency_sign_(typography) too.
    – eyescream
    May 30, 2014 at 9:56
  • Yes, @eyescream, it DOES produce something.. It seems though that the ¤ symbol only shows a '$' in my tests.. I tried changing my user currency to GBP, and the Account record's currency also [I'm playing with the AnnualRevenue field on Account], and I haven't got a £ yet..
    – CRT
    Sep 13, 2017 at 19:13
0

We could use connectApi to get currency details.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_output_features.htm

We can use default​Currency​IsoCode in ConnectApi.Features to get iso code.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_output_usersettings.htm

We can use currencySymbol in ConnectApi.UserSettings to get currency symbol.

ConnectApi.OrganizationSettings  orgSettings = ConnectApi.Organization.getSettings();
system.debug(orgSettings.UserSettings.currencySymbol);
system.debug(orgSettings.features.defaultCurrencyIsoCode);

This solution will only work in Single currency org. For multiCurrency org use userinfo.CurrencyIsoCode().

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .