How to get the default org currency in APEX

Today we are going to discuss something about the Default currency of Salesforce org. As we all know that it is setup from Setup|Company Profile|Company Information for normal currency org. i.e. org without multi currency enabled. However sometimes we might need to fetch the data in APEX for creating applications. To get the data we cannot use any class or query for this purpose. Well the task is not as hard as it seems. And I’ll demonstrate it to you, how to get the default org currency in APEX.

Apex Code

We will be doing this task with the help of a standard class UserInfo. This class is used to get a lot of information for the user like getting the user’s first name, last name, organisation name, profile id of the user, time zone, username, email, etc. This class also has a function to get the org’s default currency of the organisation the user is working in. we are going to use the very same function for that purpose.

public class OrgCurrency {
public string orgCurr {get; set;}

public OrgCurrency(){
orgCurr = UserInfo.getDefaultCurrency();
System.debug(orgCurr);
}
}

And this is it, you can see it in the debug logs that the default currency is displayed. The currency that will be fetched will be in the ISO format, like INR for Indian Rupee, and USE for United state Dollar. The function helping us here to get the required data is the getDefaultCurrency() function. Now you can use it in your packages and send them in your apps to other orgs, and use the data by fetching it dynamically, instead of statically getting it.

VF Page code

<apex:page controller="OrgCurrency">
<apex:outputText value="The default org currency is: {!orgCurr}"/>
</apex:page>

As we can see that in the visualforce page we have just printed the org currency code that we got.

Output

The output of my code is something like this:

Support

That’s all about getting the default org currency in APEX, for any further queries feel free to add a ticket at:

https://webkul.uvdesk.com/en/customer/create-ticket/

Or let us know your views on how to make this code better, in comments section below.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close

Index