GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(handler)!: name each handler by its type and remove the String constructor by dschach · Pull Request #378 · dschach/salesforce-trigger-framework

Conversation

@dschach

@dschach dschach commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner

This pull request is batch 1 of the breaking release: items 55 and 64 of the 2026-10-29 quality analysis. A handler now gets its name from its type. The new protected constructor TriggerHandler(Type handlerType) sets the name to Type.getName(), so the name always matches bypass(Type), also for an inner class. The String constructor is removed, because a typed name can have no typo and no wrong case. The no-arg constructor stays.

Changes

Handler identity

  • New protected TriggerHandler(Type handlerType). It sets the handler name to Type.getName() and needs no runtime name lookup. A null type throws TriggerHandlerException with the existing text A handler type is required.
  • TriggerHandler(String handlerName) is removed, and with it the trim of the name that it did.
  • TriggerHandler() stays. It still resolves the name from toString() when the name is first needed. That gives only the short name of an inner class, so the ApexDoc and the README say that an inner-class handler must use the Type constructor.
  • The comments of the handlerName field, the constructors, and getHandlerName() describe the 2 ways that a handler gets its name.

Sample

  • AccountSampleTriggerHandler has 1 constructor, which calls super(AccountSampleTriggerHandler.class), casts the trigger collections, and sets the loop limit. The copy of the handler in the sample README matches.

Tests

  • The test handler calls super(TriggerHandlerTest.TestHandler.class), so every bypass and loop test uses the Type constructor.
  • typeConstructorSetsFullHandlerName proves that an inner class gets the name TriggerHandlerTest.TestHandler. typeConstructorRejectsNullType proves the error for a null type.
  • noArgConstructorResolvesShortInnerClassName uses a new empty inner class, UntypedHandler, to prove that the runtime lookup gives only the short name.
  • The 3 String constructor tests are removed. The 2 base class tests use new TriggerHandler(), whose name resolves to TriggerHandler.

Documentation

  • The README examples call super(OpportunityTriggerHandler.class).
  • The new README section "Pass the Handler Class to super()" says that the value to pass is the class name followed by .class. It shows a top-level handler, an inner-class handler, and a handler with 2 constructors, each of which casts Trigger.new and Trigger.old after super(), and it says how to see the name. Its sub-section "Upgrade From the String Constructor" shows the change to make.
  • The API table lists the Type constructor and no longer lists the String constructor.

Behavior notes

  • A handler that called super('ClassName') with its exact class name gets the same name from super(ClassName.class), so its bypasses and loop counts do not change.
  • A handler that passed another name, for example a short name or the short name of an inner class, gets a different name from the Type constructor. A bypass by the old name no longer matches it. The README upgrade section says to bypass by type, and to pass ClassName.class.getName() to getLoopCount(), which has no Type form.
  • A handler that uses the no-arg constructor keeps its name.
  • Bypass names stay as the caller spelled them, with matching that ignores case. Converting them through Type.forName() was left for the batch that reworks bypassList() and bypassSet().
  • Not verified: whether Type.getName() includes the namespace prefix for a handler in a namespaced org. The scratch orgs have no namespace.
  • This is the first pull request of the breaking release. Release Please will open a release pull request for the next major version after the merge. Leave that release pull request open until the last batch is merged.

Test plan

  • Scratch org at API 67.0, after each code commit: all local tests pass, 48 of 48 in the 2 test classes of this project, with 100 percent coverage on TriggerHandler, AccountSampleTriggerHandler, and AccountSampleTrigger.
  • A temporary inner-class handler deployed from outside the repository confirmed the README text: the Type constructor gives SalesHandlers.OpportunityTriggerHandler, a handler without it gives only the short name, and bypass(SalesHandlers.OpportunityTriggerHandler.class) matches. The class was deleted from the org afterwards.
  • npm run codeanalyzer:run reports the 2 known FieldNameMatchesMethodName findings on the debug flags, which a later batch removes, and nothing new.
  • The Prettier check passes on every file in this pull request.

BREAKING CHANGE: The constructor TriggerHandler(String handlerName) is removed. A handler that calls super('HandlerName') must call super(HandlerName.class) instead, which sets the handler name to Type.getName(). A handler that passed a name other than its class name must also change the bypass calls and getLoopCount() calls that use that name.

BEGIN_NESTED_COMMIT
feat(handler): name a handler by its type with a Type constructor

The new protected constructor TriggerHandler(Type handlerType) sets the handler name to Type.getName(), so the name always matches bypass(Type), also for an inner class.
END_NESTED_COMMIT

BEGIN_NESTED_COMMIT
docs(readme): show how to pass the handler class to super()

The README explains that the value to pass is the class name followed by .class, with examples for a top-level handler, an inner-class handler, a handler with 2 constructors, and the upgrade from the String constructor.
END_NESTED_COMMIT

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Claude AI and others added 3 commits October 30, 2026 15:09
Claude AI @claude
feat(handler): name a handler by its type with a Type constructor
8f1bc01
The new protected constructor TriggerHandler(Type handlerType) sets the handler name to Type.getName(), so the name always matches bypass(Type), also for an inner class, and the runtime name lookup is not needed. The test handler and the README examples pass the class to super().

Co-Authored-By: Claude <[email protected]>
Claude AI @claude
refactor(handler)!: remove the String constructor
87547f2
The constructor TriggerHandler(String handlerName) is removed, so a handler has 2 ways to get its name: the Type constructor, which gives Type.getName(), or the runtime lookup of the no-arg constructor. The sample handler passes its class to super(), and the tests and both READMEs no longer use the String constructor.

BREAKING CHANGE: The constructor TriggerHandler(String handlerName) is removed. A handler that calls super('HandlerName') must call super(HandlerName.class) instead, which gives the name Type.getName().

Co-Authored-By: Claude <[email protected]>
Claude AI @claude
docs(readme): show how to pass the handler class to super()
e625937
The new README section explains that the value to pass is the class name followed by .class, and shows a top-level handler, an inner-class handler, a handler with 2 constructors, and the upgrade from the String constructor. The ApexDoc example of the Type constructor also shows the inner-class form.

Co-Authored-By: Claude <[email protected]>
@codecov

codecov Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b4b7781) to head (05956ef).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #378   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          254       253    -1     
=========================================
- Hits           254       253    -1     
Flag Coverage Δ
Apex 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Claude AI @claude
docs(readme): cast the trigger lists in the super() examples
05956ef
The examples that pass the handler class to super() now cast Trigger.new and Trigger.old into the handler's fields, and the handler with 2 constructors passes both lists to the constructor that calls super(). The sample README has its code blocks fixed and no line-break tags in its copy of the handler comments.

Co-Authored-By: Claude <[email protected]>
@dschach
dschach merged commit 9b47bba into main Oct 30, 2026
5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@dschach
dschach deleted the refactor/handler-type-identity branch October 30, 2026 04:34
@dschach dschach mentioned this pull request Oct 30, 2026
chore(main): release 2.0.0 #379
Merged
dschach added a commit that referenced this pull request Oct 30, 2026
@dschach
chore(main): release 2.0.0 (#379)
9de6a2e
🤖 I have created a release *beep* *boop*
---


## [2.0.0](v1.5.1...v2.0.0) (2026-10-30)


### ⚠ BREAKING CHANGES

* **handler:** The test-visible no-arg constructor TriggerHandler.LoopCounter() is removed, and setTriggerContext() and validateRun() are no longer test-visible. A test that used them must build the counter with a maximum, or run the handler with setTestContext() and run().
* **handler:** The test-visible static fields TriggerHandler.loopCountMap, TriggerHandler.bypassedHandlers, and TriggerHandler.globalBypass are removed. A test that read them must use the public methods instead: getLoopCount(), bypassList(), and isGlobalBypassed().
* **handler:** TriggerHandler is now an abstract class, so new TriggerHandler() no longer compiles. Code that built the base class directly must build a class that extends it.
* **handler:** The test-visible method setTriggerContext(System.TriggerOperation, Boolean) is removed. A test that called it to force a trigger context must call setTestContext(operation) on the handler instead.
* **handler:** beforeInsert(), beforeUpdate(), beforeDelete(), afterInsert(), afterUpdate(), afterDelete(), afterUndelete(), and andFinally() are no longer test-visible. A test that called 1 of them through a TriggerHandler reference must run the handler with setTestContext() and run(), or call the handler's own public override.
* **handler:** The test-visible fields TriggerHandler.showDebug and TriggerHandler.showLimits are renamed to TriggerHandler.doShowDebug and TriggerHandler.doShowLimits. A test that read the old names must read the new ones; no code outside tests can see these fields.
* **handler:** A maximum loop count now applies to each trigger operation separately, so 1 operation no longer uses up the count of the others. A handler that called setMaxLoopCount(2) to allow 1 run of before update and after update together must call setMaxLoopCount(1). To read the count of 1 operation, call getLoopCount(String, System.TriggerOperation).
* **handler:** getLoopCount() returns -1, not 0, for a handler or trigger operation with no call of setMaxLoopCount(). After a call with 0 or a negative value, the framework counts the runs but sets no limit. Code that compared the count with 0 to find a handler that is not counted must compare it with -1.
* **handler:** setMaxLoopCount(0) no longer stops every run of a handler; it removes the limit. To keep a handler from running, bypass it with TriggerHandler.bypass().
* **handler:** setBypass(name, false) no longer clears the global bypass, and isBypassed() no longer returns true for a handler that only the global bypass stops. To ask whether a handler will run, call isSkipped(), and to ask about the global bypass, call isGlobalBypassed().
* **handler:** bypassAll() no longer clears the named bypasses. After bypassAll() and clearGlobalBypass(), a handler that was bypassed by name before is still bypassed. To clear every bypass, call clearAllBypasses().
* **handler:** A global bypass no longer adds the entry BypassAll to bypassList() or bypassSet(). To check whether all handlers are bypassed, call isGlobalBypassed(). A test that read TriggerHandler.BYPASS_ALL_ALIAS must stop using it.
* **handler:** The constructor TriggerHandler(String handlerName) is removed. A handler that calls super('HandlerName') must call super(HandlerName.class) instead, which sets the handler name to Type.getName(). A handler that passed a name other than its class name must also change the bypass calls and getLoopCount() calls that use that name.

### Features

* **handler:** Add isGlobalBypassed() and isSkipped() to check bypasses ([33c852d](33c852d))
* **handler:** Name a handler by its type with a Type constructor ([9b47bba](9b47bba))
* **handler:** Set a bypass by type with setBypass(Type, Boolean) ([33c852d](33c852d))
* **handler:** Set and read the loop limit of 1 trigger operation ([931d336](931d336))
* **handler:** Turn on debug and limits lines for 1 handler ([79d3964](79d3964))


### Bug Fixes

* **handler:** Count the loop of each trigger operation separately ([#381](#381)) ([931d336](931d336))
* **handler:** Keep the named and global bypasses independent ([#380](#380)) ([33c852d](33c852d))
* **handler:** Keep the named bypasses when all handlers are bypassed ([33c852d](33c852d))
* **handler:** Read a maximum loop count of 0 as no limit ([931d336](931d336))
* **handler:** Return -1 from getLoopCount for an operation not counted ([931d336](931d336))
* **handler:** Say that the loop limit stopped the run in its warning ([f844349](f844349))


### Tests

* **handler:** Suppress NcssCount on the large test class ([ef55c41](ef55c41))


### Code Refactoring

* **handler:** Drop the BypassAll alias from the bypass list ([33c852d](33c852d))
* **handler:** Hold the bypasses and loop counters in inner classes ([#384](#384)) ([ef55c41](ef55c41))
* **handler:** Make TriggerHandler an abstract class ([#383](#383)) ([8845dc6](8845dc6))
* **handler:** Name each handler by its type and remove the String constructor ([#378](#378)) ([9b47bba](9b47bba))
* **handler:** Remove TestVisible from the overridable methods ([8845dc6](8845dc6))
* **handler:** Remove the testMode parameter from setTriggerContext ([8845dc6](8845dc6))
* **handler:** Remove the unused LoopCounter default and test-visible members ([#385](#385)) ([0f02565](0f02565))
* **handler:** Rename the debug flags to doShowDebug and doShowLimits ([#382](#382)) ([79d3964](79d3964))


### Documentation

* **changelog:** Remove the duplicate lines of an older release ([f844349](f844349))
* **contributing:** Say that the site is updated before each release ([fecb28b](fecb28b))
* **handler:** Add since dates and fix the see links ([f844349](f844349))
* **handler:** Correct the loop count, loop limit, and andFinally docs ([f844349](f844349))
* **handler:** Deprecate bypassSet() in favor of bypassList() ([33c852d](33c852d))
* **handler:** Deprecate debug() and limits() for the show methods ([79d3964](79d3964))
* **handler:** Deprecate getLoopCount(String) for the per-operation form ([931d336](931d336))
* **handler:** Rewrite the ApexDoc and the markdown files in simplified technical English ([#386](#386)) ([fecb28b](fecb28b))
* **handler:** Say that TriggerHandler(Type) replaces the String one ([33c852d](33c852d))
* **handler:** Say when andFinally() runs and when it does not ([931d336](931d336))
* **handler:** Say why TriggerHandler suppresses EmptyStatementBlock ([0f02565](0f02565))
* **readme:** Add the upgrade steps for handlers, triggers, and tests ([fecb28b](fecb28b))
* **readme:** Fix the site links and add contributing and license ([f844349](f844349))
* **readme:** Show how to pass the handler class to super() ([9b47bba](9b47bba))
* **repo:** Correct the documentation and comments after a prose review ([#388](#388)) ([f844349](f844349))
* **repo:** Rewrite DEPLOY, the internal READMEs, and the PR template ([fecb28b](fecb28b))
* **sample:** Copy the sample trigger and handler into the sample README ([#387](#387)) ([1c7851f](1c7851f))
* **sample:** Remove the br tags from the sample code in the README ([#389](#389)) ([99cdcb4](99cdcb4))
* **sample:** Rewrite the sample ApexDoc and README ([fecb28b](fecb28b))
* **security:** Add a security policy and the issue form links ([f844349](f844349))
* **site:** Regenerate the documentation site ([99cdcb4](99cdcb4))
* **site:** Regenerate the documentation site ([f844349](f844349))


### Build System

* **hooks:** Copy the sample code into the sample README on commit ([1c7851f](1c7851f))
* **release:** Keep the version placeholder of the bug form current ([f844349](f844349))


### Continuous Integration

* **format:** Check that the sample README shows the current sample code ([1c7851f](1c7851f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@dschach
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.