Skip to content

Commit

Permalink
Merge pull request #4085 from SalesforceFoundation/feature/spelak/W-0…
Browse files Browse the repository at this point in the history
…30505

030505: Customizable Rollups: Lingering References to Previous Fields After Modification
  • Loading branch information
rponti-sforg authored Apr 2, 2019
2 parents 30eeb7d + 9289652 commit b379f89
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 157 deletions.
2 changes: 1 addition & 1 deletion src/classes/CRLP_Batch_Base.cls
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public abstract class CRLP_Batch_Base {
// Retrieve and store the cached list of Rollup__mdt records into the Rollups Processor
// so that the list never changes throughout the life of the batch job
if (this.statefulCacheOfRollupsToBeProcessed != null) {
CRLP_Rollup_SEL.stuffRollupsByTypeCache(this.jobType, this.jobFilter,
CRLP_Rollup_SEL.addRollupsToCache(this.jobType, this.jobFilter,
this.statefulCacheOfRollupsToBeProcessed);
}

Expand Down
47 changes: 46 additions & 1 deletion src/classes/CRLP_Operation_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private class CRLP_Operation_TEST {
/**
* @description Test the static utility methods in the CRLP_Operation class
*/
static testMethod void test_static_methods() {
@IsTest
private static void test_static_methods() {
System.assertNotEquals(0, CRLP_Operation.getRollupOperationTypes().size(),
'There should be whole bunch of Rollup Operations');
System.assertEquals(1, CRLP_Operation.getAvailableTimeBoundOperationTypes(CRLP_Operation.RollupType.BEST_YEAR.name()).size(),
Expand All @@ -55,4 +56,48 @@ private class CRLP_Operation_TEST {
System.assertEquals(CRLP_Operation.RollupType.SUM, CRLP_Operation.getRollupTypeFromString('Sum'));
}

/**
* @description Verify that the picklist values of the Rollup__mdt.Operation__c field matches the Enum in the codebase
*/
@IsTest
private static void rollupCmtOperationPicklistShouldMatchEnums() {
Set<String> enumNames = new Set<String>();
for (CRLP_Operation.RollupType rollupType : CRLP_Operation.RollupType.values()) {
enumNames.add(rollupType.name());
}

Set<String> picklistValues = new Set<String>();
for (Schema.PicklistEntry picklist : Schema.SObjectType.Rollup__mdt.fields.Operation__c.getPicklistValues()) {
picklistValues.add(picklist.getValue());
}

System.assertEquals(
enumNames,
picklistValues,
'There must exist a CRLP_Operation.RollupType for each Rollup__mdt.Operation__c Picklist Value and vice versa'
);
}

/**
* @description Verify that the picklist values of the Rollup__mdt.Time_Bound_Operation_Type__c field matches
* the Enum in the codebase
*/
@IsTest
private static void timeBoundOperationTypePicklistShouldMatchEnums() {
Set<String> enumNames = new Set<String>();
for (CRLP_Operation.TimeBoundOperationType rollupType : CRLP_Operation.TimeBoundOperationType.values()) {
enumNames.add(rollupType.name());
}

Set<String> picklistValues = new Set<String>();
for (Schema.PicklistEntry picklist : Schema.SObjectType.Rollup__mdt.fields.Time_Bound_Operation_Type__c.getPicklistValues()) {
picklistValues.add(picklist.getValue());
}

System.assertEquals(
enumNames,
picklistValues,
'There must exist a CRLP_Operation.TimeBoundOperationType for each Rollup__mdt.Time_Bound_Operation_Type__c Picklist Value and vice versa'
);
}
}
13 changes: 12 additions & 1 deletion src/classes/CRLP_Query_SEL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* @group Rollups
* @group-content ../../ApexDocContent/Rollups2.htm
* @description Selector class for relevant summary/target fields for use by the Rollup Engine
*/public class CRLP_Query_SEL {
*/
public inherited sharing class CRLP_Query_SEL {

/**
* @description For a given SObject, identify all referenced fields from the currently defined Rollups and
Expand All @@ -56,19 +57,23 @@
allFieldsToQuery.add(SObjectType.Partial_Soft_Credit__c.fields.Contact__c.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Partial_Soft_Credit__c.fields.Amount__c.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Partial_Soft_Credit__c.fields.Role_Name__c.getSobjectField().getDescribe());

} else if (resultObject == Account_Soft_Credit__c.SObjectType) {
allFieldsToQuery.add(SObjectType.Account_Soft_Credit__c.fields.Opportunity__c.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Account_Soft_Credit__c.fields.Account__c.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Account_Soft_Credit__c.fields.Amount__c.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Account_Soft_Credit__c.fields.Role__c.getSobjectField().getDescribe());

} else if (resultObject == OpportunityContactRole.SObjectType) {
allFieldsToQuery.add(SObjectType.OpportunityContactRole.fields.ContactId.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.OpportunityContactRole.fields.OpportunityId.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.OpportunityContactRole.fields.Role.getSobjectField().getDescribe());

} else if (resultObject == Opportunity.SObjectType) {
allFieldsToQuery.add(SObjectType.Opportunity.fields.Amount.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Opportunity.fields.CloseDate.getSobjectField().getDescribe());
allFieldsToQuery.add(SObjectType.Opportunity.fields.npe03__Recurring_Donation__c.getSobjectField().getDescribe());

} else if (resultObject == npe01__OppPayment__c.SObjectType) {
allFieldsToQuery.add(SObjectType.npe01__OppPayment__c.fields.npe01__Opportunity__c.getSobjectField().getDescribe());
}
Expand All @@ -82,18 +87,24 @@
// Special conditions - these are foreign key fields that are supported in filters for record type and user
if (dfr.getName() == 'RecordTypeId') {
queryFields.add('RecordType.DeveloperName');

} else if (dfr.getName() == 'OwnerId') {
queryFields.add('Owner.Alias');

} else if (dfr.getName() == 'CreatedById') {
queryFields.add('CreatedBy.Alias');

} else if (dfr.getName() == 'LastModifiedById') {
queryFields.add('LastModifiedBy.Alias');

} else if (dfr.getName() == 'ContactId') {
queryFields.add('Contact.AccountId');

} else if (dfr.getName() == contactRelField) {
queryFields.add(contactRelField.replace('__c', '__r') + '.AccountId');
}
}

// Convert the Set to the List to support String.Join()
List<String> fieldsList = new List<String>(queryFields);

Expand Down
Loading

0 comments on commit b379f89

Please sign in to comment.