From f2b4a5c8762fdcc9423c34c77c545f5ec2d69455 Mon Sep 17 00:00:00 2001 From: Andrew Fawcett Date: Sun, 20 Mar 2016 14:25:26 +0000 Subject: [PATCH] Issue 280 - CalculateJobId__c not being set https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/2 80 --- rolluptool/src/classes/RollupService.cls | 7 +++++++ rolluptool/src/classes/RollupServiceTest3.cls | 3 +++ 2 files changed, 10 insertions(+) diff --git a/rolluptool/src/classes/RollupService.cls b/rolluptool/src/classes/RollupService.cls index 4f40d520..1b18fb01 100644 --- a/rolluptool/src/classes/RollupService.cls +++ b/rolluptool/src/classes/RollupService.cls @@ -105,6 +105,13 @@ global with sharing class RollupService Integer scopeSize = (Integer) DeclarativeLookupRollupSummaries__c.getInstance().CalculateJobScopeSize__c; Id jobId = Database.executeBatch(new RollupCalculateJob(lookupId, masterWhereClause), scopeSize == null ? 100 : scopeSize); + // Update CalculateJobId__c for Custom Object based rollups? + if(lookup.Record instanceof LookupRollupSummary__c) { + LookupRollupSummary__c rollupSummary = (LookupRollupSummary__c) lookup.Record; + rollupSummary.CalculateJobId__c = jobId; + update lookup.Record; + } + return jobId; } diff --git a/rolluptool/src/classes/RollupServiceTest3.cls b/rolluptool/src/classes/RollupServiceTest3.cls index c40f71d9..3b3b65e9 100644 --- a/rolluptool/src/classes/RollupServiceTest3.cls +++ b/rolluptool/src/classes/RollupServiceTest3.cls @@ -112,6 +112,9 @@ private with sharing class RollupServiceTest3 System.assert(e.getMessage().equals('A calculate job for rollup \'Test Rollup\' is already executing. If you suspect it is not aleady running try clearing the applicable record from the Lookup Rollup Calculate Jobs tab and try again.')); } Test.stopTest(); + // Assert job id cleared + rollupSummary = [select Id, CalculateJobId__c from LookupRollupSummary__c where Id = :rollupSummary.Id]; + System.assertEquals(jobId, rollupSummary.CalculateJobId__c); // Assert job cleared System.assertEquals(0, [select Id from LookupRollupCalculateJob__c].size());