Skip to content

Commit

Permalink
Fixes for two issues, 377 and 17
Browse files Browse the repository at this point in the history
#3
77
#1
7
  • Loading branch information
Andrew Fawcett authored and Andrew Fawcett committed May 28, 2017
1 parent b1ffb0a commit c588234
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rolluptool/src/classes/RollupController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public with sharing class RollupController
'trigger ' + RollupTriggerName + ' on ' + RollupSummary.ChildObject + '\n' +
' (before delete, before insert, before update, after delete, after insert, after undelete, after update)\n'+
'{\n'+
' '+ (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.triggerHandler();\n'+
' '+ (namespace.length() > 0 ? namespace + '.' : '') + 'RollupService.triggerHandler(' + RollupSummary.ChildObject + '.SObjectType);\n'+
'}\n';
}
}
Expand Down
2 changes: 1 addition & 1 deletion rolluptool/src/classes/RollupControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private class RollupControllerTest
'trigger ' + controller.RollupTriggerName + ' on ' + rollupSummary.ChildObject__c + '\n' +
' (before delete, before insert, before update, after delete, after insert, after undelete, after update)\n'+
'{\n'+
' ' + Utilities.classPrefix() + 'RollupService.triggerHandler();\n'+
' ' + Utilities.classPrefix() + 'RollupService.triggerHandler(Contact.SObjectType);\n'+
'}\n', controller.getTriggerCode());
System.assertEquals(
'/**\n' +
Expand Down
29 changes: 25 additions & 4 deletions rolluptool/src/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ global with sharing class RollupService
**/
private static boolean triggerHandleInvoked = false;

/**
* Apex Trigger helper, automatically resolves child records to process via LREngine and lookups described in RollupSummary
* also determines if based on the old trigger records if the rollup processing needs to occur
* @param childObjectType This can be used in cases where the prior overload was used an the Id.getSobjectType method fails to return the SOBjectType (see Issue 17 in the repo)
**/
global static void triggerHandler(SObjectType childObjectType)
{
triggerHandleInvoked = true;

// Currently no processing in the before phase
if(Trigger.isBefore)
return;

// Anything to rollup?
handleRollups(Trigger.oldMap, Trigger.newMap, childObjectType, new List<RollupSummaries.CalculationMode> { RollupSummaries.CalculationMode.Realtime, RollupSummaries.CalculationMode.Scheduled });
}

/**
* Apex Trigger helper, automatically resolves child records to process via LREngine and lookups described in RollupSummary
* also determines if based on the old trigger records if the rollup processing needs to occur
Expand Down Expand Up @@ -1151,17 +1168,21 @@ global with sharing class RollupService
// Resolve (and cache) SObjectType's and fields for Parent and Child objects
SObjectType parentObjectType = getSObjectType(lookup.ParentObject);
if(parentObjectType==null)
throw RollupServiceException.invalidRollup(lookup);
throw RollupServiceException.invalidRollup(lookup, 'Parent Object : ' + lookup.ParentObject);
Map<String, Schema.SObjectField> parentFields = getSObjectTypeFields(parentObjectType);
SObjectType childObjectType = getSObjectType(lookup.ChildObject);
if(childObjectType==null)
throw RollupServiceException.invalidRollup(lookup);
throw RollupServiceException.invalidRollup(lookup, 'Child Object : ' + lookup.ChildObject);
Map<String, Schema.SObjectField> childFields = getSObjectTypeFields(childObjectType);
SObjectField fieldToAggregate = childFields.get(lookup.FieldToAggregate);
SObjectField relationshipField = childFields.get(lookup.RelationshipField);
SObjectField aggregateResultField = parentFields.get(lookup.AggregateResultField);
if(fieldToAggregate==null || relationshipField==null || aggregateResultField==null)
throw RollupServiceException.invalidRollup(lookup);
if(fieldToAggregate==null)
throw RollupServiceException.invalidRollup(lookup, 'Field to Aggregate: ' + lookup.FieldToAggregate);
if(relationshipField==null)
throw RollupServiceException.invalidRollup(lookup, 'Relationship Field: ' + lookup.RelationshipField);
if(aggregateResultField==null)
throw RollupServiceException.invalidRollup(lookup, 'Aggregate Result Field: ' + lookup.AggregateResultField);

// Summary field definition used by LREngine
LREngine.RollupSummaryField rsf =
Expand Down
4 changes: 2 additions & 2 deletions rolluptool/src/classes/RollupServiceException.cls
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class RollupServiceException extends Exception
/**
* Generic exception when aspects of the rollup summary definition are found to be in error at runtime
**/
public static RollupServiceException invalidRollup(RollupSummary lookup)
public static RollupServiceException invalidRollup(RollupSummary lookup, String configInvalid)
{
return new RollupServiceException('Lookup Rollup Summary \'' + lookup.Name + '\' is invalid, your org configuration may have changed.');
return new RollupServiceException('Lookup Rollup Summary \'' + lookup.Name + '\' is invalid, your org configuration may have changed (' + configInvalid + ').');
}

/**
Expand Down

0 comments on commit c588234

Please sign in to comment.