Skip to content

Commit

Permalink
v1.5.80 - Namespace Package Updates (#476)
Browse files Browse the repository at this point in the history
* Optimizing RollupCalcItemReplacer to better protect against queries issued

* Migration script tweaks

* Fixes issue that was preventing namespaced package from being generated

* RollupCalcItemReplacerTests optimization
  • Loading branch information
jamessimone committed Aug 17, 2023
1 parent b5b84f8 commit 37dd56b
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 92 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ As well, don't miss [the Wiki](../../wiki), which includes even more info for co

## Deployment & Setup

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6kPAAS">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6kjAAC">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6kPAAS">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6kjAAC">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
8 changes: 4 additions & 4 deletions extra-tests/classes/InvocableDrivenTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ private class InvocableDrivenTests {
@IsTest
static void shouldClearParentFieldOnDelete() {
// driven by extra-tests/flows/Rollup_Integration_refresh_on_delete_clears_value.flow-meta.xml
RollupParent__c parent = new RollupParent__c(NumberField__c = 1, Name = 'Parent');
Account parent = new Account(AnnualRevenue = 1, Name = 'Parent');
insert parent;

RollupChild__c child = new RollupChild__c(RollupParent__c = parent.Id, Name = 'child');
ContactRequest child = new ContactRequest(WhatId = parent.Id);
insert child;

Test.startTest();
delete child;
Test.stopTest();

parent = [SELECT NumberField__c FROM RollupParent__c WHERE Id = :parent.Id];
System.assertEquals(null, parent.NumberField__c);
parent = [SELECT AnnualRevenue FROM Account WHERE Id = :parent.Id];
System.assertEquals(null, parent.AnnualRevenue);
}
}
4 changes: 1 addition & 3 deletions extra-tests/classes/RollupCalcItemReplacerTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ private class RollupCalcItemReplacerTests {
static final Integer ACC_ANNUAL_REVENUE = 5;
@TestSetup
static void setup() {
Rollup.defaultControl = new RollupControl__mdt(ShouldAbortRun__c = true);
insert new Account(Name = RollupCalcItemReplacerTests.class.getName(), AnnualRevenue = ACC_ANNUAL_REVENUE);
}

@IsTest
static void shouldNotTryToQueryRelationshipFieldsWhenTheyAlreadyExistOnPassedInRecords() {
Rollup.defaultControl = new RollupControl__mdt(ShouldAbortRun__c = true);
Account acc = [SELECT Id, Name FROM Account];

Contact con = new Contact(LastName = 'Lookup to Account', AccountId = acc.Id);
Expand All @@ -30,7 +30,6 @@ private class RollupCalcItemReplacerTests {

@IsTest
static void shouldSafelyRequeryRelationshipFields() {
Rollup.defaultControl = new RollupControl__mdt(ShouldAbortRun__c = true);
Account acc = [SELECT Id, Name FROM Account];

Contact con = new Contact(LastName = 'Lookup to Account', AccountId = acc.Id);
Expand Down Expand Up @@ -104,7 +103,6 @@ private class RollupCalcItemReplacerTests {

@IsTest
static void shouldRetrieveQueryFieldsPartOfOrderBy() {
Rollup.defaultControl = new RollupControl__mdt(ShouldAbortRun__c = true);
Account acc = [SELECT Id, Name FROM Account];

Contact con = new Contact(LastName = 'Ordered by Account Name', AccountId = acc.Id);
Expand Down
12 changes: 10 additions & 2 deletions extra-tests/classes/RollupFullRecalcTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,7 @@ private class RollupFullRecalcTests {

Assert.areEqual(
2,
[SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'BatchApexWorker' AND ApexClass.Name = :RollupFullBatchRecalculator.class.getName()],
[SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'BatchApexWorker' AND ApexClass.Name = :getNamespaceSafeClassName(RollupFullBatchRecalculator.class)],
'Test requires batch apex to have been the full recalc mechanism'
);
parent = [SELECT AnnualRevenue FROM Account WHERE Id = :parent.Id];
Expand Down Expand Up @@ -2702,13 +2702,21 @@ private class RollupFullRecalcTests {

Assert.areEqual(
1,
[SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'Queueable' AND ApexClass.Name = :RollupAsyncProcessor.class.getName()],
[SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'Queueable' AND ApexClass.Name = :getNamespaceSafeClassName(RollupAsyncProcessor.class)],
JSON.serializePretty([SELECT JobType, ApexClass.Name FROM AsyncApexJob])
);
parent = [SELECT AnnualRevenue FROM Account WHERE Id = :parent.Id];
Assert.areEqual(40, parent.AnnualRevenue, 'Both children types should have correctly summed to one field in full recalc');
}

private static String getNamespaceSafeClassName(Type intendedClass) {
List<String> classNameParts = intendedClass.getName().split('\\.');
if (classNameParts.size() > 1) {
classNameParts.remove(0);
}
return classNameParts[0];
}

private class DeferredContactPointAddressRollup extends RollupDeferredFullRecalcProcessor {
public DeferredContactPointAddressRollup(List<Rollup__mdt> meta, Set<String> recordIds) {
super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
<actionType>apex</actionType>
<dataTypeMappings>
<typeName>T__oldRecordsToRollup</typeName>
<typeValue>RollupChild__c</typeValue>
<typeValue>ContactRequest</typeValue>
</dataTypeMappings>
<dataTypeMappings>
<typeName>T__recordsToRollup</typeName>
<typeValue>RollupChild__c</typeValue>
<typeValue>ContactRequest</typeValue>
</dataTypeMappings>
<flowTransactionModel>CurrentTransaction</flowTransactionModel>
<inputParameters>
<name>lookupFieldOnCalcItem</name>
<value>
<stringValue>RollupParent__c</stringValue>
<stringValue>WhatId</stringValue>
</value>
</inputParameters>
<inputParameters>
Expand Down Expand Up @@ -49,7 +49,7 @@
<inputParameters>
<name>rollupFieldOnOpObject</name>
<value>
<stringValue>NumberField__c</stringValue>
<stringValue>AnnualRevenue</stringValue>
</value>
</inputParameters>
<inputParameters>
Expand All @@ -61,7 +61,7 @@
<inputParameters>
<name>rollupSObjectName</name>
<value>
<stringValue>RollupParent__c</stringValue>
<stringValue>Account</stringValue>
</value>
</inputParameters>
<nameSegment>Rollup</nameSegment>
Expand Down Expand Up @@ -113,7 +113,7 @@
<connector>
<targetReference>Add_deleted_record_to_collection</targetReference>
</connector>
<object>RollupChild__c</object>
<object>ContactRequest</object>
<recordTriggerType>Delete</recordTriggerType>
<triggerType>RecordBeforeDelete</triggerType>
</start>
Expand All @@ -124,6 +124,6 @@
<isCollection>true</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<objectType>RollupChild__c</objectType>
<objectType>ContactRequest</objectType>
</variables>
</Flow>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apex-rollup",
"version": "1.5.79",
"version": "1.5.80",
"description": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions rollup-namespaced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ For more info, see the base `README`.

## Deployment & Setup

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008So66AAC">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6koAAC">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008So66AAC">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008C6koAAC">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
7 changes: 4 additions & 3 deletions rollup-namespaced/sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"default": true,
"package": "apex-rollup-namespaced",
"path": "rollup-namespaced/source/rollup",
"versionName": "Prevents null pointer exception when cascasding rollups create a no-op rollup",
"versionName": "RollupCalcItemReplacer optimizations",
"versionNumber": "1.0.45.0",
"versionDescription": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"releaseNotesUrl": "https://github.com/jamessimone/apex-rollup/releases/latest",
Expand All @@ -24,6 +24,7 @@
"apex-rollup-namespaced@1.0.41-0": "04t6g000008SnldAAC",
"apex-rollup-namespaced@1.0.42-0": "04t6g000008SnlsAAC",
"apex-rollup-namespaced@1.0.43-0": "04t6g000008SnrcAAC",
"apex-rollup-namespaced@1.0.44-0": "04t6g000008So66AAC"
"apex-rollup-namespaced@1.0.44-0": "04t6g000008So66AAC",
"apex-rollup-namespaced@1.0.45-0": "04t6g000008C6koAAC"
}
}
}
Loading

0 comments on commit 37dd56b

Please sign in to comment.