Skip to content

Commit

Permalink
Greater tolerance for OR operators in critiera
Browse files Browse the repository at this point in the history
  • Loading branch information
afawcett committed Feb 26, 2018
1 parent 617d80d commit c416784
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rolluptool/src/classes/LREngine.cls
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public class LREngine {
// #2 Where clause
String whereClause = '';
if (ctx.detailWhereClause != null && ctx.detailWhereClause.trim().length() > 0) {
whereClause = 'AND ' + ctx.detailWhereClause ;
whereClause = 'AND (' + ctx.detailWhereClause +')';
}

// #3 Group by field
Expand Down
47 changes: 47 additions & 0 deletions rolluptool/src/classes/RollupServiceTest3.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,53 @@ private with sharing class RollupServiceTest3
System.assertEquals(expectedAmount, (Decimal) assertParents.get(parentC.id).get(aggregateResultField));
}

/**
* https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/631
**/
private testmethod static void testOrInCriteria()
{
// Test supported?
if(!TestContext.isSupported())
return;

// Configure rollup
LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c();
rollupSummary.Name = 'Total Opportunities greater than 200 into Annual Revenue on Account';
rollupSummary.ParentObject__c = 'Account';
rollupSummary.ChildObject__c = 'Opportunity';
rollupSummary.RelationShipField__c = 'AccountId';
rollupSummary.RelationShipCriteria__c = 'CloseDate < TODAY OR Amount > 100';
rollupSummary.FieldToAggregate__c = 'CloseDate';
rollupSummary.AggregateOperation__c = 'Max';
rollupSummary.AggregateResultField__c = 'SLAExpirationDate__c';
rollupSummary.Active__c = true;
rollupSummary.CalculationMode__c = 'Realtime';
insert new List<LookupRollupSummary__c> { rollupSummary };

// Test data
Account account = new Account();
account.Name = 'Test Account';
account.AnnualRevenue = 0;
insert account;
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Open';
opp.CloseDate = System.today();
opp.AccountId = account.Id;
opp.Amount = 100;
insert opp;

// Assert rollup
Id accountId = account.Id;
System.assertEquals(null, Database.query('select SLAExpirationDate__c from Account where Id = :accountId')[0].get(ACCOUNT_SLA_EXPIRATION_DATE));

// Delete Opportunity
delete opp;

// Assert rollup
System.assertEquals(null, Database.query('select SLAExpirationDate__c from Account where Id = :accountId')[0].get(ACCOUNT_SLA_EXPIRATION_DATE));
}

/**
* Create test user
**/
Expand Down

0 comments on commit c416784

Please sign in to comment.