Skip to content

Feedback#3

Closed
CloudCodeAcademy wants to merge 0 commit into
mainfrom
feedback
Closed

Feedback#3
CloudCodeAcademy wants to merge 0 commit into
mainfrom
feedback

Conversation

@CloudCodeAcademy
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@walters954 walters954 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handleTitleNormalization by 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 added isNewLead/hasEmailChanged guards, along with the IsConverted check to prevent re-processing.

Thorough Test Coverage

  • You wrote both positive and negative test cases for handleTitleNormalization and handleAutoLeadScoring — this is exactly the right approach.
  • Your handleLeadAutoConvertOneMatchUnitTest and handleLeadAutoConvertTwoMatcheshUnitTest tests cover the two critical scenarios well.
  • You're using Assert.areEqual with 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 @isTest as well.

Proper Trigger Structure

  • The LeadTrigger correctly separates before/after logic and passes Trigger.oldMap to handleLeadAutoConvert — 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.cls
  • force-app/main/default/classes/LeadTriggerHandlerTest.cls
  • force-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 handleTitleNormalization receives 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 handleLeadAutoConvert handles that correctly.

Thinking through edge cases like these is what separates good developers from great ones — keep it up!

  • Wally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants