Feedback#3
Conversation
walters954
left a comment
There was a problem hiding this comment.
Hi Irene! 👋
Great work on this Testing & Debugging module! You clearly put serious thought into both debugging the LeadTriggerHandler class and writing a comprehensive test suite. The fact that you identified multiple intentional bugs and fixed them — and wrote both positive and negative test scenarios — is impressive work.
What You Did Well ✅
Strong Debugging Skills
- You correctly identified and fixed the null-pointer issue in
handleTitleNormalizationby pre-filtering leads with non-null titles before the loop — great defensive coding! - In
handleAutoLeadScoring, you caught two real bugs: initializing score to 10 instead of 0 (which would allow scores to exceed 18), and using=assignment instead of+=(which meant only the last condition counted). Both fixes are exactly right. - In
handleLeadAutoConvert, you identified the recursion risk and correctly addedisNewLead/hasEmailChangedguards, along with theIsConvertedcheck to prevent re-processing.
Thorough Test Coverage
- You wrote both positive and negative test cases for
handleTitleNormalizationandhandleAutoLeadScoring— this is exactly the right approach. - Your
handleLeadAutoConvertOneMatchUnitTestandhandleLeadAutoConvertTwoMatcheshUnitTesttests cover the two critical scenarios well. - You're using
Assert.areEqualwith descriptive messages, which makes test failures much easier to diagnose.
Proper @isTest Annotation
- The test class is correctly annotated with
@isTest, and each test method has@isTestas well.
Proper Trigger Structure
- The
LeadTriggercorrectly separates before/after logic and passesTrigger.oldMaptohandleLeadAutoConvert— a clean, well-structured trigger.
Areas for Improvement 🚀
1. Use Test.startTest() / Test.stopTest() (Currently Commented Out)
I noticed Test.startTest() and Test.stopTest() are commented out in most of your tests. These are important for a few reasons:
- They reset governor limits for the code under test, giving you a fresh set of DML/query limits.
- They ensure async processes (like future methods, queueable jobs) complete before your assertions.
- They make it clear to other developers exactly which code is being tested.
For example, in handleTitleNormalizationCorrectionUnitTest:
// Recommended pattern:
insert leads;
Test.startTest();
LeadTriggerHandler.handleTitleNormalization(leads);
Test.stopTest();
// Then assert...2. Submission Format — Use .cls Files Instead of a Single Text File
Your code was submitted in a single week11 file rather than as proper Apex .cls files in the force-app/main/default/classes/ directory. For real-world Salesforce development and for your future modules, always structure your code as individual files:
force-app/main/default/classes/LeadTriggerHandler.clsforce-app/main/default/classes/LeadTriggerHandlerTest.clsforce-app/main/default/triggers/LeadTrigger.trigger
This ensures Salesforce CLI (sf deploy) and version control tooling work correctly.
3. Minor: Assertion Argument Order
In Apex, Assert.areEqual(expected, actual, message) — the expected value comes first. In a couple of your lead auto-convert tests the arguments appear reversed (e.g., Assert.areEqual(nonConvertedLead.IsConverted, false, ...)). While this works, reversing them means error messages say "Expected: false, Actual: false" which is confusing. Swap to Assert.areEqual(false, nonConvertedLead.IsConverted, ...) for clarity.
4. Consider Test Data Isolation with @testSetup
Right now each test method inserts its own data. As test suites grow, this can get repetitive and slow. Consider using a @testSetup method to create shared test data that is rolled back after the class runs:
@testSetup
static void setupData() {
// Insert shared leads, contacts, accounts here
}Your Next Challenge 🎯
You did a solid job with both positive and negative test paths. For your next step, try thinking about edge cases:
- What happens if
handleTitleNormalizationreceives an empty list? Does it still work gracefully? - What if a lead has a title of
"vp manager"— which normalization wins? Write a test that proves your understanding of the behavior. - What if two leads in the same batch have the same email as two different contacts? Add a test to prove
handleLeadAutoConverthandles that correctly.
Thinking through edge cases like these is what separates good developers from great ones — keep it up!
- Wally
No description provided.