@@ -32,6 +32,9 @@ private class RollupMultiCurrencyTests {
32
32
33
33
@IsTest
34
34
static void shouldCorrectlyRollupMaxForMultiCurrency () {
35
+ if (hasCurrencyInfo (' EUR' ) == false ) {
36
+ return ;
37
+ }
35
38
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
36
39
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
37
40
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -81,6 +84,9 @@ private class RollupMultiCurrencyTests {
81
84
82
85
@IsTest
83
86
static void shouldCorrectlyRollupMinForMultiCurrency () {
87
+ if (hasCurrencyInfo (' EUR' ) == false ) {
88
+ return ;
89
+ }
84
90
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
85
91
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
86
92
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -131,6 +137,9 @@ private class RollupMultiCurrencyTests {
131
137
132
138
@IsTest
133
139
static void shouldCorrectlyRollupSumForMultiCurrency () {
140
+ if (hasCurrencyInfo (' EUR' ) == false ) {
141
+ return ;
142
+ }
134
143
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
135
144
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
136
145
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -182,6 +191,9 @@ private class RollupMultiCurrencyTests {
182
191
183
192
@IsTest
184
193
static void shouldCorrectlyRollupAverageForMultiCurrency () {
194
+ if (hasCurrencyInfo (' EUR' ) == false ) {
195
+ return ;
196
+ }
185
197
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
186
198
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
187
199
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -240,6 +252,9 @@ private class RollupMultiCurrencyTests {
240
252
241
253
@IsTest
242
254
static void shouldCorrectlyRollupFirstForMultiCurrency () {
255
+ if (hasCurrencyInfo (' EUR' ) == false ) {
256
+ return ;
257
+ }
243
258
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
244
259
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
245
260
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -300,6 +315,9 @@ private class RollupMultiCurrencyTests {
300
315
301
316
@IsTest
302
317
static void shouldCorrectlyRollupLastForMultiCurrency () {
318
+ if (hasCurrencyInfo (' EUR' ) == false ) {
319
+ return ;
320
+ }
303
321
Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
304
322
System .assertEquals (null , acc .AnnualRevenue , ' Test has started under the wrong conditions!' );
305
323
System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
@@ -358,6 +376,62 @@ private class RollupMultiCurrencyTests {
358
376
System .assertEquals (lastOpportunityId , acc .Name , ' Should have taken last based on multi-currency Amount! Records: ' + opportunities );
359
377
}
360
378
379
+ @IsTest
380
+ static void properlyTracksCurrencyItemsForDifferentParentCurrencies () {
381
+ if (hasCurrencyInfo (' EUR' ) == false || hasCurrencyInfo (' JPY' ) == false ) {
382
+ return ;
383
+ }
384
+ delete [SELECT Id FROM Opportunity ];
385
+
386
+ Account acc = (Account ) RollupTestUtils .queryRecord (Account .SObjectType , new List <Schema .SObjectField >{ Account .AnnualRevenue });
387
+ acc .AnnualRevenue = 100 ;
388
+ update acc ;
389
+ System .assertEquals (' USD' , getCurrencyIsoCode (acc ), ' Test has started under the wrong conditions!' );
390
+
391
+ Opportunity eurOpp = new Opportunity (Name = ' First Parent' , StageName = ' a' , CloseDate = System .today (), AccountId = acc .Id );
392
+ RollupCurrencyInfo .setCurrencyIsoCode (eurOpp , ' EUR' );
393
+ Contract contract = new Contract (AccountId = acc .Id , Name = ' Second Parent' );
394
+ RollupCurrencyInfo .setCurrencyIsoCode (contract , ' JPY' );
395
+ insert new List <SObject >{ eurOpp , contract };
396
+
397
+ Rollup .onlyUseMockMetadata = true ;
398
+ Rollup__mdt firstParent = new Rollup__mdt (
399
+ RollupFieldOnCalcItem__c = ' AnnualRevenue' ,
400
+ LookupObject__c = ' Opportunity' ,
401
+ LookupFieldOnCalcItem__c = ' Id' ,
402
+ LookupFieldOnLookupObject__c = ' AccountId' ,
403
+ RollupFieldOnLookupObject__c = ' Amount' ,
404
+ RollupOperation__c = ' SUM' ,
405
+ CalcItem__c = ' Account'
406
+ );
407
+ Rollup__mdt secondParent = new Rollup__mdt (
408
+ RollupFieldOnCalcItem__c = ' AnnualRevenue' ,
409
+ LookupObject__c = ' Contract' ,
410
+ LookupFieldOnCalcItem__c = ' Id' ,
411
+ LookupFieldOnLookupObject__c = ' AccountId' ,
412
+ RollupFieldOnLookupObject__c = ' ContractTerm' ,
413
+ RollupOperation__c = ' SUM' ,
414
+ CalcItem__c = ' Account'
415
+ );
416
+ Rollup .rollupMetadata = new List <Rollup__mdt >{ firstParent , secondParent };
417
+ Rollup .apexContext = TriggerOperation .AFTER_INSERT ;
418
+ Rollup .shouldRun = true ;
419
+ Rollup .records = new List <Account >{ acc };
420
+
421
+ Test .startTest ();
422
+ Rollup .runFromTrigger ();
423
+ Test .stopTest ();
424
+
425
+ contract = [SELECT ContractTerm FROM Contract WHERE Id = : contract .Id ];
426
+ eurOpp = [SELECT Amount FROM Opportunity WHERE Id = : eurOpp .Id ];
427
+ System .assertNotEquals (null , contract .ContractTerm , ' Rollup should have occurred' );
428
+ System .assertNotEquals (contract .ContractTerm , eurOpp .Amount );
429
+ }
430
+
431
+ private static Boolean hasCurrencyInfo (String currencyCode ) {
432
+ return RollupCurrencyInfo .getCurrencyInfo (currencyCode ).IsoCode != null ;
433
+ }
434
+
361
435
private static String getCurrencyIsoCode (SObject record ) {
362
436
return UserInfo .isMultiCurrencyOrganization () ? (String ) record .get (RollupCurrencyInfo .CURRENCY_ISO_CODE_FIELD_NAME ) : ' USD' ;
363
437
}
0 commit comments