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?
Attribution to: pjcarly
Possible Suggestion/Solution #1
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.
Attribution to: eyescream
Possible Suggestion/Solution #2
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;
}
Attribution to: pjcarly
Possible Suggestion/Solution #3
We could use connectApi to get currency details.
We can use defaultCurrencyIsoCode in ConnectApi.Features to get iso code.
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().
Attribution to: Manjot Singh
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4448