From 7584ca2bf7edbc73a9ff9aa0f78e2f69288ace35 Mon Sep 17 00:00:00 2001 From: Christian Carter Date: Mon, 23 Nov 2015 15:03:49 -0800 Subject: [PATCH] Add ID type knowledge to LREngine --- rolluptool/src/classes/LREngine.cls | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 +}