Skip to content

Commit

Permalink
Fixed issue using currency rollups in a community context
Browse files Browse the repository at this point in the history
#4
54
  • Loading branch information
Andrew Fawcett authored and Andrew Fawcett committed May 28, 2017
1 parent c361bc4 commit 59409d0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions rolluptool/src/classes/LREngine.cls
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,22 @@ public class LREngine {
// Currency lookup
static final Map<String,Decimal> currencyConversionMap = new Map<String,Decimal>();
private static Decimal convertCurrency(String iso, Decimal val) {
if(currencyConversionMap.isEmpty()){
String query = 'select IsoCode, ConversionRate from CurrencyType where IsActive = true';
for(sObject ct : Database.query(query))
currencyConversionMap.put((String)ct.get('IsoCode'), (Decimal)ct.get('ConversionRate'));
}
return val!=null ? val * currencyConversionMap.get(iso) : 0;
return new ConvertCurrencyHelper().convertCurrencyWithoutSharing(iso, val);
}

/**
* See here for the reason why this has to run "without sharing" https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/454
**/
private without sharing class ConvertCurrencyHelper {
private Decimal convertCurrencyWithoutSharing(String iso, Decimal val) {
if(currencyConversionMap.isEmpty()){
String query = 'select IsoCode, ConversionRate from CurrencyType where IsActive = true';
for(sObject ct : Database.query(query))
currencyConversionMap.put((String)ct.get('IsoCode'), (Decimal)ct.get('ConversionRate'));
}
return val!=null ? val * currencyConversionMap.get(iso) : 0;
}
}

/**
Key driver method that rolls up lookup fields based on the context. This is specially useful in Trigger context.
Expand Down

0 comments on commit 59409d0

Please sign in to comment.