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?

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.

  • I was actually hoping of getting the € somehow :) – pjcarly Nov 15 '12 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 '14 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 '14 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 '17 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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