Skip to content

Refactor validation exceptions#691

Open
sonalguptaabd-bit wants to merge 2 commits intotrailheadapps:mainfrom
sonalguptaabd-bit:refactor-validation-exceptions
Open

Refactor validation exceptions#691
sonalguptaabd-bit wants to merge 2 commits intotrailheadapps:mainfrom
sonalguptaabd-bit:refactor-validation-exceptions

Conversation

@sonalguptaabd-bit
Copy link

What does this PR do?

  • Refactors Opportunity validation to use custom exception classes (OpportunityValidationException)
    instead of addError for better separation of concerns.
  • Implements OpportunityTriggerHandler to handle exceptions and display proper error messages.
  • Improves readability and maintainability, aligns with handler/service pattern.

Testing

  • Closed Won stage probability validation tested.
  • Discount > 50% validation tested.
  • Valid Opportunity insert tested.
  • All tests pass.

Before

  • Validation used opp.addError directly inside service class.

After

  • Validation throws custom exceptions.
  • Trigger handler catches exceptions and calls addError for user-friendly messages.

@sonalguptaabd-bit sonalguptaabd-bit requested a review from a team as a code owner January 25, 2026 16:33
@muenzpraeger
Copy link

Hey @sonalguptaabd-bit, thank you for your contributions! As a good open-source practice I recommend to first create issues around to be proposed changes, so that the maintainers can discuss those first.

@sonalguptaabd-bit
Copy link
Author

Hi @muenzpraeger, thanks for the suggestion.

I’ve opened an issue to document and discuss this refactor approach so it can be reviewed first as recommended.
Please let me know if you’d like any changes to the PR based on that discussion.

Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants