Skip to content

Commit

Permalink
Merge pull request #261 from cdcarter/master
Browse files Browse the repository at this point in the history
Allow First/Last Summaries to work on Id and Reference Fields
  • Loading branch information
afawcett committed Nov 29, 2015
2 parents 4bc42b6 + b4f7ac1 commit bf0e007
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions rolluptool/src/classes/LREngine.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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');
}
}

Expand All @@ -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
Expand Down Expand Up @@ -592,4 +602,4 @@ public class LREngine {
}
}

}
}
6 changes: 3 additions & 3 deletions rolluptool/src/classes/TestLREngine.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 {
Expand Down Expand Up @@ -997,4 +997,4 @@ private class TestLREngine {
System.assertEquals(expected1, reloadedAcc3.get(rollupField.master.getName()));
System.assertEquals(expected2, reloadedAcc4.get(rollupField.master.getName()));
}
}
}

0 comments on commit bf0e007

Please sign in to comment.