Find your content:

Search form

You are here

Multiple currency in Managed package without breaking support for non-currency orgs?


I want to implement support for Multi Currency in a Managed Package, while still allowing support for regular orgs without multi currency enabled.

Does anybody have any experience with this scenario?

If I avoid any static references to multi currency fields in my Visualforce pages and Apex code, will I still be able to install into regular orgs without multi currency enabled?

I've read the Salesforce documentation regarding this, and it's not 100% clear what would happen in this scenario. Getting it wrong is potentially an irreversible mistake.

Attribution to: James Davies

Possible Suggestion/Solution #1

Your right James, you need to use dynamic SOQL and to test the org for a presents of multi-currency related fields.

For example, wrap your methods that reference multi-currency objects in a check for an element that is only available in orgs that have multi-currency enabled (I'm using DatedConversionRate here, but there might be a schema type that is more specific, this is just the first one I could think of):

global Boolean checkMCEnabled(){
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
    Schema.SObjectType mcEnabled = gd.get('DatedConversionRate');
    return (mcEnabled != null) ? true : false;

Also remember to make sure none of your webservices return a type related to multicurrency because you can't deprecate them from managed packages and you'll have to have them enabled to install (just a little tip from personal expirence!)

Attribution to: jordan.baucke

Possible Suggestion/Solution #2

You might also be interested in this Apex Enterprise pattern we presented at Dreamforce this year. If you follow the Selector pattern to manage your database query code. It automatically handles multi-currency for you in the SObjectSelector base class. Useful to ensure during your development process no hard references slip into your queries without you noticing! ;-)

After that just avoid explicit references (in code and VF pages) to CurrencyIsoCode and other MC standard or advanced objects via dynamic apex. There is a good flag on the the UserInfo class for this and is used by the above code.



public static String getCurrencyFromObject(SObject someObject)
     return Userinfo.isMultiCurrencyOrganization() ?
         (String) someObject.get('CurrencyIsoCode') : UserInfo.getDefaultCurrency();

Further Implementation Note: If you want to encapsulate and specialise this behaviour further around a specific object take a look at the Domain pattern also described by the same article above. The above util method could be added to the SObjectDomain base class for example.

Attribution to: Andrew Fawcett
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content