From c6196e3e9cebc7e88b0945fe246a607bfac56634 Mon Sep 17 00:00:00 2001 From: Andrew Fawcett Date: Sat, 7 Feb 2015 22:35:48 +0000 Subject: [PATCH] Various fixes https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/1 15 - Done https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/1 08 - Done https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/1 07 - Done https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/1 03 - Done (Upgraded to latest API) --- .../classes/ApexClassesSelector.cls-meta.xml | 2 +- .../classes/ApexTriggersSelector.cls-meta.xml | 2 +- .../AsyncApexJobsSelector.cls-meta.xml | 2 +- rolluptool/src/classes/LREngine.cls | 24 +++++- rolluptool/src/classes/LREngine.cls-meta.xml | 2 +- .../src/classes/MetadataService.cls-meta.xml | 2 +- .../classes/MetadataServiceTest.cls-meta.xml | 2 +- .../RollupCalculateController.cls-meta.xml | 2 +- .../classes/RollupCalculateJob.cls-meta.xml | 2 +- .../src/classes/RollupController.cls-meta.xml | 2 +- .../classes/RollupControllerTest.cls-meta.xml | 2 +- rolluptool/src/classes/RollupJob.cls-meta.xml | 2 +- .../src/classes/RollupJobTest.cls-meta.xml | 2 +- .../src/classes/RollupService.cls-meta.xml | 2 +- .../RollupServiceException.cls-meta.xml | 2 +- rolluptool/src/classes/RollupServiceTest.cls | 29 +------ .../classes/RollupServiceTest.cls-meta.xml | 2 +- .../classes/RollupServiceTest2.cls-meta.xml | 2 +- .../classes/RollupServiceTest3.cls-meta.xml | 2 +- rolluptool/src/classes/RollupSummaries.cls | 42 +++++++--- .../src/classes/RollupSummaries.cls-meta.xml | 2 +- .../RollupSummariesSelector.cls-meta.xml | 2 +- .../src/classes/RollupSummariesTest.cls | 76 +++++++++++++++++-- .../classes/RollupSummariesTest.cls-meta.xml | 2 +- ...llupSummaryEnhancedController.cls-meta.xml | 2 +- ...SummaryEnhancedControllerTest.cls-meta.xml | 2 +- ...pSummaryScheduleItemsSelector.cls-meta.xml | 2 +- .../src/classes/SObjectDomain.cls-meta.xml | 2 +- .../classes/SObjectDomainTest.cls-meta.xml | 2 +- .../src/classes/SObjectSelector.cls-meta.xml | 2 +- .../classes/SObjectSelectorTest.cls-meta.xml | 2 +- .../src/classes/StringBuilder.cls-meta.xml | 2 +- .../src/classes/TestContext.cls-meta.xml | 2 +- .../src/classes/TestLREngine.cls-meta.xml | 2 +- .../classes/WelcomeController.cls-meta.xml | 2 +- .../WelcomeControllerTest.cls-meta.xml | 2 +- .../src/components/zip.component-meta.xml | 2 +- .../components/zipEntry.component-meta.xml | 2 +- .../src/pages/managetrigger.page-meta.xml | 7 +- .../src/pages/rollupcalculate.page-meta.xml | 2 +- .../pages/rollupsummaryenhanced.page-meta.xml | 7 +- .../rollupsummaryenhancednew.page-meta.xml | 2 +- rolluptool/src/pages/welcome.page-meta.xml | 7 +- ...RollupServiceTest2Trigger.trigger-meta.xml | 2 +- ...RollupServiceTest3Trigger.trigger-meta.xml | 2 +- .../RollupServiceTestTrigger.trigger-meta.xml | 2 +- .../RollupSummariesTrigger.trigger-meta.xml | 2 +- 47 files changed, 166 insertions(+), 106 deletions(-) diff --git a/rolluptool/src/classes/ApexClassesSelector.cls-meta.xml b/rolluptool/src/classes/ApexClassesSelector.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/ApexClassesSelector.cls-meta.xml +++ b/rolluptool/src/classes/ApexClassesSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/ApexTriggersSelector.cls-meta.xml b/rolluptool/src/classes/ApexTriggersSelector.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/ApexTriggersSelector.cls-meta.xml +++ b/rolluptool/src/classes/ApexTriggersSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/AsyncApexJobsSelector.cls-meta.xml b/rolluptool/src/classes/AsyncApexJobsSelector.cls-meta.xml index 1124945f..08d159fb 100644 --- a/rolluptool/src/classes/AsyncApexJobsSelector.cls-meta.xml +++ b/rolluptool/src/classes/AsyncApexJobsSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/classes/LREngine.cls b/rolluptool/src/classes/LREngine.cls index 05d0e056..8ec090a4 100644 --- a/rolluptool/src/classes/LREngine.cls +++ b/rolluptool/src/classes/LREngine.cls @@ -60,7 +60,7 @@ public class LREngine { for(sObject ct : Database.query(query)) currencyConversionMap.put((String)ct.get('IsoCode'), (Decimal)ct.get('ConversionRate')); } - return val * currencyConversionMap.get(iso); + return val!=null ? val * currencyConversionMap.get(iso) : 0; } /** @@ -82,7 +82,7 @@ public class LREngine { } return rollUp(ctx, masterRecordIds); } - + /** Key driver method that rolls up lookup fields based on the context. This is meant to be called from non trigger contexts like scheduled/batch apex, where we want to rollup on some master record ids. @@ -93,6 +93,20 @@ public class LREngine { because we want client or calling code to have this freedom to do some post processing and update when required. */ public static Sobject[] rollUp(Context ctx, Set masterIds) { + return rollUp(ctx, masterIds, false); + } + + /** + Key driver method that rolls up lookup fields based on the context. This is meant to be called from non trigger contexts like + scheduled/batch apex, where we want to rollup on some master record ids. + + @param Context the complete context required to rollup + @param masterIds Master record IDs whose child records should be rolled up. + @param validateOnly Checks the SOQL query is valid, throws an exception if not, returns null if valid + @returns Array of in memory master objects. These objects are not updated back to the database + because we want client or calling code to have this freedom to do some post processing and update when required. + */ + public static Sobject[] rollUp(Context ctx, Set masterIds, Boolean validateOnly) { // Clone this since we are about to modify it later masterIds = masterIds.clone(); // K: Id of master record @@ -141,6 +155,12 @@ public class LREngine { String soql = String.format(SOQL_TEMPLATE, new String[]{soqlProjection, detailTblName, whereClause, grpByFld}); System.debug('SOQL is ' + soql); + // validate only? + if(validateOnly) { + Database.getQueryLocator(soql); + return null; + } + // aggregated results List results = Database.query(soql); diff --git a/rolluptool/src/classes/LREngine.cls-meta.xml b/rolluptool/src/classes/LREngine.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/LREngine.cls-meta.xml +++ b/rolluptool/src/classes/LREngine.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/MetadataService.cls-meta.xml b/rolluptool/src/classes/MetadataService.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/MetadataService.cls-meta.xml +++ b/rolluptool/src/classes/MetadataService.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/MetadataServiceTest.cls-meta.xml b/rolluptool/src/classes/MetadataServiceTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/MetadataServiceTest.cls-meta.xml +++ b/rolluptool/src/classes/MetadataServiceTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupCalculateController.cls-meta.xml b/rolluptool/src/classes/RollupCalculateController.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupCalculateController.cls-meta.xml +++ b/rolluptool/src/classes/RollupCalculateController.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupCalculateJob.cls-meta.xml b/rolluptool/src/classes/RollupCalculateJob.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupCalculateJob.cls-meta.xml +++ b/rolluptool/src/classes/RollupCalculateJob.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupController.cls-meta.xml b/rolluptool/src/classes/RollupController.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupController.cls-meta.xml +++ b/rolluptool/src/classes/RollupController.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupControllerTest.cls-meta.xml b/rolluptool/src/classes/RollupControllerTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupControllerTest.cls-meta.xml +++ b/rolluptool/src/classes/RollupControllerTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupJob.cls-meta.xml b/rolluptool/src/classes/RollupJob.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupJob.cls-meta.xml +++ b/rolluptool/src/classes/RollupJob.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupJobTest.cls-meta.xml b/rolluptool/src/classes/RollupJobTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupJobTest.cls-meta.xml +++ b/rolluptool/src/classes/RollupJobTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupService.cls-meta.xml b/rolluptool/src/classes/RollupService.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupService.cls-meta.xml +++ b/rolluptool/src/classes/RollupService.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupServiceException.cls-meta.xml b/rolluptool/src/classes/RollupServiceException.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupServiceException.cls-meta.xml +++ b/rolluptool/src/classes/RollupServiceException.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupServiceTest.cls b/rolluptool/src/classes/RollupServiceTest.cls index 98ce8dc0..f64fe2b6 100644 --- a/rolluptool/src/classes/RollupServiceTest.cls +++ b/rolluptool/src/classes/RollupServiceTest.cls @@ -680,7 +680,6 @@ private with sharing class RollupServiceTest // Sample various limits prior to an update Integer beforeQueries = Limits.getQueries(); Integer beforeRows = Limits.getQueryRows(); - Integer beforeDescribes = Limits.getFieldsDescribes(); // Update opportunities (no changes to the field being aggregted, thus no rollup processng) update opps; @@ -688,7 +687,6 @@ private with sharing class RollupServiceTest // Assert no further limits have been used since the field to aggregate on the detail has not changed System.assertEquals(beforeQueries + 1, Limits.getQueries()); // Only tolerate a query for the Lookup definition System.assertEquals(beforeRows + 1, Limits.getQueryRows()); // Only tolerate a row for the Lookup definition - System.assertEquals(beforeDescribes, Limits.getFieldsDescribes()); // Zero tolerance on field describes } private testmethod static void testLimitsConsumedWithConditions() @@ -762,10 +760,11 @@ private with sharing class RollupServiceTest // One query on ApexTrigger (in the TestContext.isSupported method) // One query on ApexTrigger (validation when inserting rollups) + // One query on Database.newQueryLocator (validation when insert rollup a) // One query on Rollup object // One query on Opportunity for rollup a // One query on Opportunity for rollup b - System.assertEquals(5, Limits.getQueries()); + System.assertEquals(6, Limits.getQueries()); // One row for ApexTrigger (in the TestContext.isSupported method) // One row for ApexTrigger @@ -773,13 +772,6 @@ private with sharing class RollupServiceTest // Two rows for Opportunity for rollup a // Four rows for Opportunity for rollup b System.assertEquals(10, Limits.getQueryRows()); - - // One for the statics at the top of the test - // One for the parent object validation on insert of lookup - // One for the child object validaiton on insert of lookup - // One for the lookup of the field type for the parent object during trigger - // One for the lookup of the field type for the child object during trigger - System.assertEquals(5, Limits.getFieldsDescribes()); // Assert rollup Id accountId = account.Id; @@ -795,16 +787,12 @@ private with sharing class RollupServiceTest // + One query for the Account query above // + One query on Rollup object // + One query on Opportunity for rollup a - System.assertEquals(8, Limits.getQueries()); + System.assertEquals(9, Limits.getQueries()); // + One query for the Account query above // + Two rows for Rollup object // + Two rows for Opportunity for rollup a System.assertEquals(15, Limits.getQueryRows()); - - // + One for the lookup of the field type for the parent object during trigger - // + One for the lookup of the field type for the child object during trigger - System.assertEquals(7, Limits.getFieldsDescribes()); // Assert rollup accountResult = Database.query('select AnnualRevenue, NumberOfLocations__c from Account where Id = :accountId'); @@ -892,13 +880,6 @@ private with sharing class RollupServiceTest // Two rows for Rollup object // Four rows for Opportunity for rollup a and b System.assertEquals(8, Limits.getQueryRows()); - - // One for the statics at the top of the test - // One for the parent object validation on insert of lookup - // One for the child object validaiton on insert of lookup - // One for the lookup of the field type for the parent object during trigger - // One for the lookup of the field type for the child object during trigger - System.assertEquals(5, Limits.getFieldsDescribes()); // Assert rollup Id accountId = account.Id; @@ -920,10 +901,6 @@ private with sharing class RollupServiceTest // + Two rows for Rollup object // + Four rows for Opportunity for rollup a and System.assertEquals(15, Limits.getQueryRows()); - - // + One for the lookup of the field type for the parent object during trigger - // + One for the lookup of the field type for the child object during trigger - System.assertEquals(7, Limits.getFieldsDescribes()); // Assert rollup accountResult = Database.query('select AnnualRevenue, NumberOfLocations__c from Account where Id = :accountId'); diff --git a/rolluptool/src/classes/RollupServiceTest.cls-meta.xml b/rolluptool/src/classes/RollupServiceTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupServiceTest.cls-meta.xml +++ b/rolluptool/src/classes/RollupServiceTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupServiceTest2.cls-meta.xml b/rolluptool/src/classes/RollupServiceTest2.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupServiceTest2.cls-meta.xml +++ b/rolluptool/src/classes/RollupServiceTest2.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupServiceTest3.cls-meta.xml b/rolluptool/src/classes/RollupServiceTest3.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupServiceTest3.cls-meta.xml +++ b/rolluptool/src/classes/RollupServiceTest3.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummaries.cls b/rolluptool/src/classes/RollupSummaries.cls index 7391c736..6ac7563e 100644 --- a/rolluptool/src/classes/RollupSummaries.cls +++ b/rolluptool/src/classes/RollupSummaries.cls @@ -77,13 +77,8 @@ public with sharing class RollupSummaries extends SObjectDomain **/ public override void onValidate() { - // Query for any related Apex triggers + // Cache Apex Describes and calculate child object tigger names Set rollupTriggerNames = new Set(); - for(LookupRollupSummary__c lookupRollupSummary : (List) Records) - rollupTriggerNames.add(makeTriggerName(lookupRollupSummary)); - Map apexTriggers = new ApexTriggersSelector().selectByName(rollupTriggerNames); - - // Cache Apex Describes Map gd = Schema.getGlobalDescribe(); Map> gdFields = new Map>(); for(LookupRollupSummary__c lookupRollupSummary : (List) Records) @@ -94,7 +89,13 @@ public with sharing class RollupSummaries extends SObjectDomain gdFields.put(parentObjectType, parentObjectType.getDescribe().fields.getMap()); if(childObjectType!=null && !gdFields.containsKey(childObjectType)) gdFields.put(childObjectType, childObjectType.getDescribe().fields.getMap()); + // Calculate trigger name child object reqquires in order to check existance + if(childObjectType!=null) + rollupTriggerNames.add(makeTriggerName(lookupRollupSummary)); } + + // Query for any related Apex triggers + Map apexTriggers = new ApexTriggersSelector().selectByName(rollupTriggerNames); for(LookupRollupSummary__c lookupRollupSummary : (List) Records) { @@ -134,12 +135,15 @@ public with sharing class RollupSummaries extends SObjectDomain lookupRollupSummary.AggregateResultField__c.addError(error('Field does not exist.', lookupRollupSummary, LookupRollupSummary__c.AggregateResultField__c)); } // Cannot activate Realtime or Scheduled rollup without the required trigger deployed - String triggerName = makeTriggerName(lookupRollupSummary); - if(lookupRollupSummary.Active__c && - (lookupRollupSummary.CalculationMode__c == CalculationMode.Realtime.name() || - lookupRollupSummary.CalculationMode__c == CalculationMode.Scheduled.name()) && - !apexTriggers.containsKey(triggerName)) - lookupRollupSummary.Active__c.addError(error('Apex Trigger ' + triggerName + ' has not been deployed. Click Manage Child Trigger and try again.', lookupRollupSummary, LookupRollupSummary__c.Active__c)); + if(childObjectType!=null) + { + String triggerName = makeTriggerName(lookupRollupSummary); + if(lookupRollupSummary.Active__c && + (lookupRollupSummary.CalculationMode__c == CalculationMode.Realtime.name() || + lookupRollupSummary.CalculationMode__c == CalculationMode.Scheduled.name()) && + !apexTriggers.containsKey(triggerName)) + lookupRollupSummary.Active__c.addError(error('Apex Trigger ' + triggerName + ' has not been deployed. Click Manage Child Trigger and try again.', lookupRollupSummary, LookupRollupSummary__c.Active__c)); + } // Check the list of fields expressed in the relationship critiera fields if(childObjectFields!=null && lookupRollupSummary.RelationshipCriteriaFields__c!=null) { @@ -173,6 +177,18 @@ public with sharing class RollupSummaries extends SObjectDomain aggregateResultField.getDescribe(), fieldToAggregate.getDescribe(), OPERATION_PICKLIST_TO_ENUMS.get(lookupRollupSummary.AggregateOperation__c))); + // Validate the SOQL + if(lookupRollupSummary.RelationShipCriteria__c!=null && + lookupRollupSummary.RelationShipCriteria__c.length()>0) + { + try { + // Validate only mode ensures no query is actually made should it be valid + LREngine.rollUp(lreContext, new Set(), true); + } catch (QueryException e) { + lookupRollupSummary.RelationShipCriteria__c.addError( + error(String.format(MSG_INVALID_CRITERIA, new String[] { lookupRollupSummary.RelationShipCriteria__c, e.getMessage() }), lookupRollupSummary, LookupRollupSummary__c.RelationShipCriteria__c)); + } + } } } catch (LREngine.BadRollUpSummaryStateException e) @@ -182,6 +198,8 @@ public with sharing class RollupSummaries extends SObjectDomain } } } + + private static final String MSG_INVALID_CRITERIA = 'Relationship Criteria \'\'{0}\'\' is not valid, see SOQL documentation http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_conditionexpression.htm, error is \'\'{1}\'\''; public class Constructor implements SObjectDomain.IConstructable { diff --git a/rolluptool/src/classes/RollupSummaries.cls-meta.xml b/rolluptool/src/classes/RollupSummaries.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummaries.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummaries.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummariesSelector.cls-meta.xml b/rolluptool/src/classes/RollupSummariesSelector.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummariesSelector.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummariesSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummariesTest.cls b/rolluptool/src/classes/RollupSummariesTest.cls index 962b498a..ca178665 100644 --- a/rolluptool/src/classes/RollupSummariesTest.cls +++ b/rolluptool/src/classes/RollupSummariesTest.cls @@ -33,7 +33,63 @@ private with sharing class RollupSummariesTest // TODO: Write a test to validate the criteria fields are specified when criteria is specified // ... - + + /** + * Issue https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/108 + **/ + private testmethod static void testBadCriteria() + { + // Test supported? + if(!TestContext.isSupported()) + return; + + LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c(); + rollupSummary.Name = 'Total Opportunities into Annual Revenue on Account'; + rollupSummary.ParentObject__c = 'Account'; + rollupSummary.ChildObject__c = 'Opportunity'; + rollupSummary.RelationShipField__c = 'AccountId'; + rollupSummary.RelationShipCriteria__c = 'StageName Equals Won'; + rollupSummary.RelationShipCriteriaFields__c = 'StageName'; + rollupSummary.FieldToAggregate__c = 'Amount'; + rollupSummary.AggregateOperation__c = 'Sum'; + rollupSummary.AggregateResultField__c = 'AnnualRevenue'; + rollupSummary.Active__c = true; + rollupSummary.CalculationMode__c = 'Realtime'; + SObjectDomain.Test.Database.onInsert(new LookupRollupSummary__c[] { rollupSummary } ); + SObjectDomain.triggerHandler(RollupSummaries.class); + System.assertEquals(1, SObjectDomain.Errors.getAll().size()); + System.assertEquals('Relationship Criteria \'StageName Equals Won\' is not valid, see SOQL documentation http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_conditionexpression.htm, error is \'unexpected token: \'Equals\'\'', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(LookupRollupSummary__c.RelationShipCriteria__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[0]).field); + } + + /** + * Issue https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/115 + **/ + private testmethod static void testInsertBadChildBigName() + { + // Test supported? + if(!TestContext.isSupported()) + return; + + LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c(); + rollupSummary.Name = 'Max Birthday for Contacts related to an Account'; + rollupSummary.ParentObject__c = 'Account'; + rollupSummary.ChildObject__c = 'BadBadBadBadBadBadBadBadBadBad'; + rollupSummary.RelationShipField__c = 'AccountId'; + rollupSummary.RelationShipCriteria__c = null; + rollupSummary.FieldToAggregate__c = 'LastCURequestDate'; + rollupSummary.AggregateOperation__c = 'Count'; + rollupSummary.AggregateResultField__c = 'AnnualRevenue'; + rollupSummary.RelationshipCriteriaFields__c = 'Bad'; + rollupSummary.Active__c = false; + rollupSummary.CalculationMode__c = 'Realtime'; + SObjectDomain.Test.Database.onInsert(new LookupRollupSummary__c[] { rollupSummary } ); + SObjectDomain.triggerHandler(RollupSummaries.class); + System.assertEquals(1, SObjectDomain.Errors.getAll().size()); + System.assertEquals('Object does not exist.', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(LookupRollupSummary__c.ChildObject__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[0]).field); + } + /** * Issue https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/97 **/ @@ -129,11 +185,9 @@ private with sharing class RollupSummariesTest rollupSummary.CalculationMode__c = 'Realtime'; SObjectDomain.Test.Database.onInsert(new LookupRollupSummary__c[] { rollupSummary } ); SObjectDomain.triggerHandler(RollupSummaries.class); - System.assertEquals(2, SObjectDomain.Errors.getAll().size()); + System.assertEquals(1, SObjectDomain.Errors.getAll().size()); System.assertEquals('Object does not exist.', SObjectDomain.Errors.getAll()[0].message); System.assertEquals(LookupRollupSummary__c.ChildObject__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[0]).field); - System.assertEquals('Apex Trigger ' + RollupSummaries.makeTriggerName(rollupSummary) + ' has not been deployed. Click Manage Child Trigger and try again.', SObjectDomain.Errors.getAll()[1].message); - System.assertEquals(LookupRollupSummary__c.Active__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[1]).field); } private testmethod static void testInsertRelationshipFieldValidation() @@ -292,8 +346,11 @@ private with sharing class RollupSummariesTest rollupSummary.CalculationMode__c = 'Realtime'; SObjectDomain.Test.Database.onInsert(new LookupRollupSummary__c[] { rollupSummary } ); SObjectDomain.triggerHandler(RollupSummaries.class); - System.assertEquals(1, SObjectDomain.Errors.getAll().size()); - System.assertEquals('Field Stage does not exist on the child object.', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(2, SObjectDomain.Errors.getAll().size()); + System.assertEquals('Field Stage does not exist on the child object.', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(LookupRollupSummary__c.RelationShipCriteriaFields__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[0]).field); + System.assertEquals('Relationship Criteria \'Stage = \'Won\'\' is not valid, see SOQL documentation http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_conditionexpression.htm, error is \'No such column \'Stage\' on entity \'Opportunity\'. If you are attempting to use a custom field, be sure to append the \'__c\' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.\'', SObjectDomain.Errors.getAll()[1].message); + System.assertEquals(LookupRollupSummary__c.RelationShipCriteria__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[1]).field); } private testmethod static void testRelationshipCriteriaFieldsValidationMulti() @@ -316,8 +373,11 @@ private with sharing class RollupSummariesTest rollupSummary.CalculationMode__c = 'Realtime'; SObjectDomain.Test.Database.onInsert(new LookupRollupSummary__c[] { rollupSummary } ); SObjectDomain.triggerHandler(RollupSummaries.class); - System.assertEquals(1, SObjectDomain.Errors.getAll().size()); - System.assertEquals('Fields Stage,Another do not exist on the child object.', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(2, SObjectDomain.Errors.getAll().size()); + System.assertEquals('Fields Stage,Another do not exist on the child object.', SObjectDomain.Errors.getAll()[0].message); + System.assertEquals(LookupRollupSummary__c.RelationShipCriteriaFields__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[0]).field); + System.assertEquals('Relationship Criteria \'Stage = \'Won\'\' is not valid, see SOQL documentation http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_conditionexpression.htm, error is \'No such column \'Stage\' on entity \'Opportunity\'. If you are attempting to use a custom field, be sure to append the \'__c\' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.\'', SObjectDomain.Errors.getAll()[1].message); + System.assertEquals(LookupRollupSummary__c.RelationShipCriteria__c, ((SObjectDomain.FieldError)SObjectDomain.Errors.getAll()[1]).field); } private testmethod static void testInsertCountByCloseDateNoErrors() diff --git a/rolluptool/src/classes/RollupSummariesTest.cls-meta.xml b/rolluptool/src/classes/RollupSummariesTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummariesTest.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummariesTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummaryEnhancedController.cls-meta.xml b/rolluptool/src/classes/RollupSummaryEnhancedController.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummaryEnhancedController.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummaryEnhancedController.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummaryEnhancedControllerTest.cls-meta.xml b/rolluptool/src/classes/RollupSummaryEnhancedControllerTest.cls-meta.xml index 1124945f..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummaryEnhancedControllerTest.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummaryEnhancedControllerTest.cls-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/classes/RollupSummaryScheduleItemsSelector.cls-meta.xml b/rolluptool/src/classes/RollupSummaryScheduleItemsSelector.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/RollupSummaryScheduleItemsSelector.cls-meta.xml +++ b/rolluptool/src/classes/RollupSummaryScheduleItemsSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/SObjectDomain.cls-meta.xml b/rolluptool/src/classes/SObjectDomain.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/SObjectDomain.cls-meta.xml +++ b/rolluptool/src/classes/SObjectDomain.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/SObjectDomainTest.cls-meta.xml b/rolluptool/src/classes/SObjectDomainTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/SObjectDomainTest.cls-meta.xml +++ b/rolluptool/src/classes/SObjectDomainTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/SObjectSelector.cls-meta.xml b/rolluptool/src/classes/SObjectSelector.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/SObjectSelector.cls-meta.xml +++ b/rolluptool/src/classes/SObjectSelector.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/SObjectSelectorTest.cls-meta.xml b/rolluptool/src/classes/SObjectSelectorTest.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/SObjectSelectorTest.cls-meta.xml +++ b/rolluptool/src/classes/SObjectSelectorTest.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/StringBuilder.cls-meta.xml b/rolluptool/src/classes/StringBuilder.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/StringBuilder.cls-meta.xml +++ b/rolluptool/src/classes/StringBuilder.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/TestContext.cls-meta.xml b/rolluptool/src/classes/TestContext.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/TestContext.cls-meta.xml +++ b/rolluptool/src/classes/TestContext.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/TestLREngine.cls-meta.xml b/rolluptool/src/classes/TestLREngine.cls-meta.xml index b211a092..08d159fb 100644 --- a/rolluptool/src/classes/TestLREngine.cls-meta.xml +++ b/rolluptool/src/classes/TestLREngine.cls-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active diff --git a/rolluptool/src/classes/WelcomeController.cls-meta.xml b/rolluptool/src/classes/WelcomeController.cls-meta.xml index 1124945f..08d159fb 100644 --- a/rolluptool/src/classes/WelcomeController.cls-meta.xml +++ b/rolluptool/src/classes/WelcomeController.cls-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/classes/WelcomeControllerTest.cls-meta.xml b/rolluptool/src/classes/WelcomeControllerTest.cls-meta.xml index 1124945f..08d159fb 100644 --- a/rolluptool/src/classes/WelcomeControllerTest.cls-meta.xml +++ b/rolluptool/src/classes/WelcomeControllerTest.cls-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/components/zip.component-meta.xml b/rolluptool/src/components/zip.component-meta.xml index d8da543d..8b8b6b1e 100644 --- a/rolluptool/src/components/zip.component-meta.xml +++ b/rolluptool/src/components/zip.component-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 diff --git a/rolluptool/src/components/zipEntry.component-meta.xml b/rolluptool/src/components/zipEntry.component-meta.xml index d068a2be..1b5f5272 100644 --- a/rolluptool/src/components/zipEntry.component-meta.xml +++ b/rolluptool/src/components/zipEntry.component-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 diff --git a/rolluptool/src/pages/managetrigger.page-meta.xml b/rolluptool/src/pages/managetrigger.page-meta.xml index 1650e5f6..40e6d19c 100644 --- a/rolluptool/src/pages/managetrigger.page-meta.xml +++ b/rolluptool/src/pages/managetrigger.page-meta.xml @@ -1,10 +1,5 @@ - 28.0 + 32.0 - - 1 - 5 - umlcanvas - diff --git a/rolluptool/src/pages/rollupcalculate.page-meta.xml b/rolluptool/src/pages/rollupcalculate.page-meta.xml index c987ed36..11d52dee 100644 --- a/rolluptool/src/pages/rollupcalculate.page-meta.xml +++ b/rolluptool/src/pages/rollupcalculate.page-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 diff --git a/rolluptool/src/pages/rollupsummaryenhanced.page-meta.xml b/rolluptool/src/pages/rollupsummaryenhanced.page-meta.xml index af991d3e..a5f5fc2f 100644 --- a/rolluptool/src/pages/rollupsummaryenhanced.page-meta.xml +++ b/rolluptool/src/pages/rollupsummaryenhanced.page-meta.xml @@ -1,10 +1,5 @@ - 28.0 + 32.0 - - 1 - 5 - umlcanvas - diff --git a/rolluptool/src/pages/rollupsummaryenhancednew.page-meta.xml b/rolluptool/src/pages/rollupsummaryenhancednew.page-meta.xml index 6e7a21ad..ff11c0a5 100644 --- a/rolluptool/src/pages/rollupsummaryenhancednew.page-meta.xml +++ b/rolluptool/src/pages/rollupsummaryenhancednew.page-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 diff --git a/rolluptool/src/pages/welcome.page-meta.xml b/rolluptool/src/pages/welcome.page-meta.xml index dcb1aecf..b88e882c 100644 --- a/rolluptool/src/pages/welcome.page-meta.xml +++ b/rolluptool/src/pages/welcome.page-meta.xml @@ -1,10 +1,5 @@ - 28.0 + 32.0 - - 1 - 5 - umlcanvas - diff --git a/rolluptool/src/triggers/RollupServiceTest2Trigger.trigger-meta.xml b/rolluptool/src/triggers/RollupServiceTest2Trigger.trigger-meta.xml index a015c13b..be45c9e1 100644 --- a/rolluptool/src/triggers/RollupServiceTest2Trigger.trigger-meta.xml +++ b/rolluptool/src/triggers/RollupServiceTest2Trigger.trigger-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/triggers/RollupServiceTest3Trigger.trigger-meta.xml b/rolluptool/src/triggers/RollupServiceTest3Trigger.trigger-meta.xml index a015c13b..be45c9e1 100644 --- a/rolluptool/src/triggers/RollupServiceTest3Trigger.trigger-meta.xml +++ b/rolluptool/src/triggers/RollupServiceTest3Trigger.trigger-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/triggers/RollupServiceTestTrigger.trigger-meta.xml b/rolluptool/src/triggers/RollupServiceTestTrigger.trigger-meta.xml index a015c13b..be45c9e1 100644 --- a/rolluptool/src/triggers/RollupServiceTestTrigger.trigger-meta.xml +++ b/rolluptool/src/triggers/RollupServiceTestTrigger.trigger-meta.xml @@ -1,5 +1,5 @@ - 24.0 + 32.0 Active diff --git a/rolluptool/src/triggers/RollupSummariesTrigger.trigger-meta.xml b/rolluptool/src/triggers/RollupSummariesTrigger.trigger-meta.xml index 9a6de2a6..be45c9e1 100644 --- a/rolluptool/src/triggers/RollupSummariesTrigger.trigger-meta.xml +++ b/rolluptool/src/triggers/RollupSummariesTrigger.trigger-meta.xml @@ -1,5 +1,5 @@ - 28.0 + 32.0 Active