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 contact us at:

https://wedgecommerce.com/contact-us/

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

Leave A Reply

Please verify that you are not a robot.

Tell us about Your Company

How can we help you with your business?




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home