diff --git a/rolluptool/src/classes/RollupController.cls b/rolluptool/src/classes/RollupController.cls index ad6a3dd5..4b8b6edf 100644 --- a/rolluptool/src/classes/RollupController.cls +++ b/rolluptool/src/classes/RollupController.cls @@ -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'; } } diff --git a/rolluptool/src/classes/RollupControllerTest.cls b/rolluptool/src/classes/RollupControllerTest.cls index 1465cecd..75784698 100644 --- a/rolluptool/src/classes/RollupControllerTest.cls +++ b/rolluptool/src/classes/RollupControllerTest.cls @@ -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' + diff --git a/rolluptool/src/classes/RollupService.cls b/rolluptool/src/classes/RollupService.cls index 18a782b5..8dd44cba 100644 --- a/rolluptool/src/classes/RollupService.cls +++ b/rolluptool/src/classes/RollupService.cls @@ -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.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 @@ -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 parentFields = getSObjectTypeFields(parentObjectType); SObjectType childObjectType = getSObjectType(lookup.ChildObject); if(childObjectType==null) - throw RollupServiceException.invalidRollup(lookup); + throw RollupServiceException.invalidRollup(lookup, 'Child Object : ' + lookup.ChildObject); Map 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 = diff --git a/rolluptool/src/classes/RollupServiceException.cls b/rolluptool/src/classes/RollupServiceException.cls index 5775f2ef..9af0bc0c 100644 --- a/rolluptool/src/classes/RollupServiceException.cls +++ b/rolluptool/src/classes/RollupServiceException.cls @@ -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 + ').'); } /**