Skip to content

Commit 9380eaf

Browse files
authored
Merge pull request apex-enterprise-patterns#132 from amarchbanks/feature/dynamic_currency_iso_code_soql
Changed behavior on how currency ISO code fields are added to SOQL qu…
2 parents 4a49d07 + 183329c commit 9380eaf

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

fflib/src/classes/fflib_SObjectSelector.cls

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@ public abstract with sharing class fflib_SObjectSelector
3131
implements fflib_ISObjectSelector
3232
{
3333
/**
34-
* This overrides the Multi Currency handling, preventing it from injecting the CurrencyIsoCode fie ld for certain System objects that don't ever support it
34+
* Indicates whether the sObject has the currency ISO code field for organisations which have multi-currency
35+
* enabled.
3536
**/
36-
private static Set<String> STANDARD_WITHOUT_CURRENCYISO = new Set<String> {'ApexClass', 'ApexTrigger', 'AsyncApexJob', 'Attachment', 'RecordType', 'User'};
37+
private Boolean CURRENCY_ISO_CODE_ENABLED {
38+
get {
39+
if(CURRENCY_ISO_CODE_ENABLED == null){
40+
CURRENCY_ISO_CODE_ENABLED = describeWrapper.getFieldsMap().keySet().contains('CurrencyIsoCode');
41+
}
42+
return CURRENCY_ISO_CODE_ENABLED;
43+
}
44+
set;
45+
}
3746

3847
/**
3948
* Should this selector automatically include the FieldSet fields when building queries?
@@ -323,8 +332,7 @@ public abstract with sharing class fflib_SObjectSelector
323332
for(SObjectField field : getSObjectFieldList())
324333
queryFactory.selectField(relationshipFieldPath + '.' + field.getDescribe().getName());
325334
// Automatically select the CurrencyIsoCode for MC orgs (unless the object is a known exception to the rule)
326-
if(Userinfo.isMultiCurrencyOrganization() &&
327-
!STANDARD_WITHOUT_CURRENCYISO.contains(getSObjectType().getDescribe().getName()))
335+
if(Userinfo.isMultiCurrencyOrganization() && CURRENCY_ISO_CODE_ENABLED)
328336
queryFactory.selectField(relationshipFieldPath+'.CurrencyIsoCode');
329337
}
330338

@@ -389,8 +397,7 @@ public abstract with sharing class fflib_SObjectSelector
389397
queryFactory.selectFieldSet(fieldSet);
390398

391399
// Automatically select the CurrencyIsoCode for MC orgs (unless the object is a known exception to the rule)
392-
if(Userinfo.isMultiCurrencyOrganization() &&
393-
!STANDARD_WITHOUT_CURRENCYISO.contains(getSObjectType().getDescribe().getName()))
400+
if(Userinfo.isMultiCurrencyOrganization() && CURRENCY_ISO_CODE_ENABLED)
394401
queryFactory.selectField('CurrencyIsoCode');
395402
}
396403

0 commit comments

Comments
 (0)