Replies: 3 comments
-
your test class should look like this: @IsTest
private class ApexRollupAccountTest {
@TestSetup
static void setup() {
upsert new RollupSettings__c(IsEnabled__c = true);
}
@IsTest
static void triggerIntegratesSuccessfully() {
Test.startTest();
insert new Account(
Name = 'Test Account',
Tax_Code__c = 'ICOU78'
);
Test.stopTest();
Assert.areEqual(0, Rollup.CACHED_ROLLUPS.size());
}
} There's a lot of information to digest; I totally get it. I will have to go through your feedback here and see what I'd like to incorporate. |
Beta Was this translation helpful? Give feedback.
-
Hi @jamessimone - I saw in v.1.6.0 release notes that the README was updated pertaining to this. Can you just let me know (or point me to where) what changes were incorporated so I can review? |
Beta Was this translation helpful? Give feedback.
-
@baobao917 sorry for the confusion. Here's what I was referencing:
I removed that snippet, as it was out of date. I am still planning to further update the README and wiki with a more thorough testing baseline example based on the rest of your feedback above. |
Beta Was this translation helpful? Give feedback.
-
Hi @jamessimone . This is a follow-up to #512 .
Since it is necessary to write an apex trigger for any parent objects where merging is supported (Account, Case, Contact, Lead), it would be helpful if there were more clear instructions on how to create test classes for them (geared towards an audience of non-developers, i.e. consultants, admins, adminelepors).
One nice feature of DLRS is that when you deployed the trigger it also created the test class for you. While I understand (from a prior thread) that this is one of the core issues with DLRS performance/limitations, one of the reasons why DLRS has such a high adoption rate is that you don't need a coding/developer background to use.
Since it is common to create rollups where the parent is one of those 4 standard objects, per #512 , it is almost always going to require an apex trigger and therefore an accompanying test class. I've created the trigger pretty easily based on the README documentation, however creating the test class has proven to be significantly more difficult (I'm not a developer).
I have reviewed the documentation and have found the following interspersed which may or may not be relevant:
DEPLOYMENT & SETUP section
YOUTUBE VIDEO TUTORIAL section
PARENT LEVEL MERGES section
-- Although in this section the code snippet is only for an (after delete) trigger, per Account/Case/Contact/Lead - Flow vs apex trigger? #512 discussion, the best practice is to have a trigger with all of the trigger contexts
-- This snippet which I'm not sure where it fits into this use case/discussion
QUESTIONS:
Account apex trigger
trigger ApexRollupAccountTrigger on Account(after insert, after update, before delete, after delete, after undelete) {
// after delete is required ONLY if your org does Account / Contact / Lead / Case merges
Rollup.runFromTrigger();
// etc. You can invoke the above from your handler if you have one
}
Test class (with screenshot of error)
@istest
private class ApexRollupAccountTest
{
@testsetup
static void setup() {
upsert new RollupSettings__c(IsEnabled__c = true);
// —— DATA PREPARATION ——
// insert 1 Account
Account acct = new Account(
Name = 'Test Account',
Tax_Code__c = 'ICOU78');
insert acct;
// Force the ApexRollupAccountTrigger to be invoked, fails the test if org config or other Apex code prevents this.
Test.startTest();
ApexRollupAccountTrigger(new Account());
Test.stopTest();
}
}
SUGGESTIONS:
Beta Was this translation helpful? Give feedback.
All reactions