diff --git a/rolluptool/src/classes/LREngine.cls b/rolluptool/src/classes/LREngine.cls index 8a2ba059..8e07f0e2 100644 --- a/rolluptool/src/classes/LREngine.cls +++ b/rolluptool/src/classes/LREngine.cls @@ -372,6 +372,8 @@ public class LREngine { public boolean isMasterTypeCurrency; public boolean isMasterTypeText; public boolean isDetailTypeText; + public boolean isMasterTypeId; + public boolean isDetailTypeId; public RollupSummaryField(Schema.Describefieldresult m, Schema.Describefieldresult d, RollupOperation op) { @@ -396,6 +398,8 @@ public class LREngine { this.isMasterTypeCurrency = isCurrency(master.getType()); this.isMasterTypeText = isText(master.getType()); this.isDetailTypeText = isText(detail.getType()); + this.isMasterTypeId = isIdOrReference(master.getType()); + this.isDetailTypeId = isIdOrReference(detail.getType()); // validate if field is good to work on later validate(); } @@ -414,8 +418,9 @@ public class LREngine { if (operation == RollupOperation.First || operation == RollupOperation.Last) { if ( (this.master.getType() != this.detail.getType()) && - (!isDetailTypeText && !isMasterTypeText) ) { - throw new BadRollUpSummaryStateException('Master and detail fields must be the same field type (or text based) for First or Last operations'); + ((!isDetailTypeText && !isDetailTypeId) || + (!isMasterTypeText && !isMasterTypeId))) { + throw new BadRollUpSummaryStateException('Master and detail fields must be the same field type (or text/Id based) for First or Last operations'); } } @@ -440,6 +445,11 @@ public class LREngine { dt == Schema.Displaytype.Picklist || dt == Schema.Displaytype.MultiPicklist; } + + boolean isIdOrReference (Schema.Displaytype dt) { + return dt == Schema.DisplayType.ID || + dt == Schema.DisplayType.REFERENCE; + } boolean isNumber (Schema.Displaytype dt) { return dt == Schema.Displaytype.Currency @@ -592,4 +602,4 @@ public class LREngine { } } -} \ No newline at end of file +} diff --git a/rolluptool/src/classes/TestLREngine.cls b/rolluptool/src/classes/TestLREngine.cls index f6b442da..013c3ca9 100644 --- a/rolluptool/src/classes/TestLREngine.cls +++ b/rolluptool/src/classes/TestLREngine.cls @@ -711,7 +711,7 @@ private class TestLREngine { LREngine.RollupOperation.Last)); System.assert(false, 'Expecting an exception'); } catch (Exception e) { - System.assertEquals('Master and detail fields must be the same field type (or text based) for First or Last operations', e.getMessage()); + System.assertEquals('Master and detail fields must be the same field type (or text/Id based) for First or Last operations', e.getMessage()); } try { LREngine.Context ctx = @@ -724,7 +724,7 @@ private class TestLREngine { LREngine.RollupOperation.First)); System.assert(false, 'Expecting an exception'); } catch (Exception e) { - System.assertEquals('Master and detail fields must be the same field type (or text based) for First or Last operations', e.getMessage()); + System.assertEquals('Master and detail fields must be the same field type (or text/Id based) for First or Last operations', e.getMessage()); } // Master and detail field type match try { @@ -997,4 +997,4 @@ private class TestLREngine { System.assertEquals(expected1, reloadedAcc3.get(rollupField.master.getName())); System.assertEquals(expected2, reloadedAcc4.get(rollupField.master.getName())); } -} \ No newline at end of file +}