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 — docs(sample): copy the sample trigger and handler into the sample README by dschach · Pull Request #387 · dschach/salesforce-trigger-framework

Conversation

@dschach

@dschach dschach commented Oct 30, 2026

Copy link
Copy Markdown
Owner

The sample README shows the code of the sample trigger and handler again, so the sample page of the documentation site shows it too. A script copies the code from the real files, so the copy cannot go out of date as the old hand copy did.

Changes

  • sample-handler/README.md: the sections The Trigger and The Handler each hold a copy of the file, between a START sample-code marker and an END sample-code marker. The path in the marker names the file.

  • scripts/sync-sample-code.mjs: a new script that copies each file between its markers and formats the README with Prettier. With --index, it reads the staged files. With --check, it changes nothing and fails when the README is not current.

  • .husky/pre-commit: when a sample file or the sample README is staged, the hook runs the script with --index and stages the README. It stops when the README has unstaged changes, because those would be staged too.

  • scripts/prepareApexDox.sh: runs the script before it builds the sample page.

  • .github/workflows/ci.yml: the format-lint job runs the script with --check.

  • CONTRIBUTING.md: says that the hook copies the sample code.

Behavior notes

Prettier changes the tabs in a code block of a markdown file to 2 spaces. So the copy in the README is indented with spaces, and the script formats the README with Prettier to give the same result as the commit hook and the Prettier check.

A hand edit between the markers is replaced at the next commit that stages a sample file or the README.

Test plan

  • With a change staged in the handler and a second change not staged, the hook copied only the staged change and left the README with no unstaged changes.

  • With an unstaged change in the README, the hook stopped with a message.

  • A hand edit of the code between the markers was replaced by the hook.

  • node scripts/sync-sample-code.mjs --check passes on the committed tree, and the Prettier check passes.

  • marked renders both copies as Apex code blocks and the markers as HTML comments.

BEGIN_NESTED_COMMIT
build(hooks): copy the sample code into the sample README on commit

The pre-commit hook and npm run prepareApexDox copy the staged sample trigger and handler into the sample README.
END_NESTED_COMMIT
BEGIN_NESTED_COMMIT
ci(format): check that the sample README shows the current sample code

The format-lint job fails when the code in the sample README is not the same as the sample files.
END_NESTED_COMMIT

Sorry, something went wrong.

Uh oh!

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

All reactions
Claude AI @claude
docs(sample): copy the sample trigger and handler into the sample README
8aa892f
The sample README shows the code of the sample trigger and handler again. The script scripts/sync-sample-code.mjs copies each file between 2 markers and formats the README with Prettier, so the copy cannot go out of date.

The pre-commit hook runs the script when a sample file or the sample README is staged, and it reads the staged files. npm run prepareApexDox runs it before it builds the sample page of the site. The format-lint job of CI runs it with --check and fails when the README is not current.

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

Uh oh!

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

@dschach
dschach deleted the docs/sample-readme-code branch October 30, 2026 09:02
@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.