Multi-Currency

As discussed in Chapter 2, Leveraging Platform Features, enabling and referencing certain platform features can create dependencies on your package, which require your customers to also enable those features prior to installation, and this might not always be desirable. One such feature is Multi-Currency. Once this is enabled, every object gains a CurrencyISOCode field; it then also appears on layouts, reports, and so on. Salesforce ensures that subscribers are fully aware of the implications before enabling it.

If you want to leverage it in your application (but do not think it will be something that all your customers will require), you have the option to reference this field using Dynamic Apex and Dynamic SOQL. It is in this latter area that the fflib_SObjectSelector base class provides some assistance.

You might want to consider the approach described here when working with Personal Accounts, as certain fields on the Account object are only present if this feature is enabled.

If you explicitly listed the CurrencyISOCode field in your getSObjectFieldList method, you will, therefore, bind your code and the package that contains it to this platform feature. Instead, what the base class does is use the UserInfo.isMultiCurrencyOrganization method to dynamically include this field in the SOQL query that it executes. Note that you still need to utilize Dynamic Apex to retrieve the field value, as shown in the following code:

List<Team__c> teams = (List<Team__c>)  
   new TeamsSelector().selectSObjectsById(teamIds); 
for(Team__c team : teams) { 
   String teamCurrency =  
      UserInfo.isMultiCurrencyOrganization() ? 
        (String) team.get('CurrencyIsoCode') : 
        UserInfo.getDefaultCurrency(); 
}

For Domain logic, you might want to put a common method in your own Domain base class (such as the ApplicationDomain class described in the last chapter). This way, you can encapsulate the preceding turnery operation into a single method. The sample code for this chapter contains the ApplicationDomain.getCurrencyCodes method, which can be used as follows:

public override onBeforeInsert() { 
  Map<Id, String> currencies = getCurrencyCodes(); 
  for(Team__c team : (List<Team__c>) Records) {  
    String teamCurrency = currencies.get(team.Id); 
  } 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.9.148