10

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.

11

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!)

|improve this answer|||||
  • 2
    I think you can also verify it based on existence of CurrencyIsoCode on every object and the CurrencyType table. Funny, my org is multicurrency but doesn't use dated conv. rates and still I can see this object in the database. – eyescream Nov 2 '12 at 7:16
  • Yes, CurrencyIsoCode is my preference as well. This is present if the org has Multi-Currency or Advanced Multi-Currency enabled. – Andrew Fawcett Nov 2 '12 at 8:09
11

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.

Userinfo.isMultiCurrencyOrganization()

e.g.

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.

|improve this answer|||||

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.