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(sample): rewrite the sample to show the framework in use by dschach · Pull Request #366 · dschach/salesforce-trigger-framework

Conversation

@dschach

@dschach dschach commented Oct 29, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Owner

The sample trigger and handler are the first code a new user copies, but they showed none of the framework's features. The trigger turned on the limits and debug output that the README says not to leave on. The handler changed names to upper case and then to lower case, and it queried the Contacts of Accounts that were just inserted, which is always empty. This pull request rewrites the sample so that it shows a bypass, a loop limit, andFinally(), and the old records in use, each proved by a test. It also makes data access in the handler examples explicit: system mode on every query and DML statement. It covers item 15 and the sample part of item 52 of the 2026-10-29 quality analysis. TriggerHandler.cls does not change.

Changes

Sample trigger and handler

  • The trigger has no logic: it creates the handler and calls run(). It lists all 7 contexts, even the ones the handler does not override, so it is written once and never edited again. A new override in the handler runs without a change to the trigger.
  • Before insert, the handler removes extra spaces from each Account name. Before update, it does the same only for the names that changed, which it finds with the old records.
  • After update, the handler copies a changed phone number to the child Accounts. It bypasses itself by type for that update, so the update does not run the handler again, and a finally block clears the bypass. A child Account in the same update as its parent is left out, because a trigger cannot update the records it is running for.
  • The constructor sets a loop limit of 100 as a named constant. Its comment explains that each context and each chunk of 200 records uses 1 run, so the limit does not stop a bulk update of up to 10,000 records.
  • andFinally() records each finished operation with the protected getTriggerEvent(), and the test reads that record as its call log.
  • The handler is inherited sharing. The query names WITH SYSTEM_MODE, and the DML statement names AccessLevel.SYSTEM_MODE.

Sample test

  • The test class has 10 tests, 1 for each behavior, all with real DML and Assert.areEqual: name clean-up on insert, on a changed name, and not on an unchanged name; the phone copy; the child in the same update; no second run of the handler for the child update; the cleared bypass; andFinally() after all 7 contexts, delete and undelete included; a bulk insert of 250 records inside the loop limit; and the 2 constructors.
  • 1 test bypasses the handler to insert a name with extra spaces, which shows how a test uses the bypass API to set up data.

Documentation

  • The README tells readers to list all 7 contexts in a trigger, so that the trigger is written once and never edited again, and to leave out only the contexts that an object does not support. It said before to list only the contexts the handler overrides. All 4 trigger examples list the 7 contexts.
  • The README handler examples use WITH SYSTEM_MODE and AccessLevel.SYSTEM_MODE instead of user mode. A new Data access section explains why: a trigger runs without sharing, so an inherited sharing handler does too, and a handler often must change records that the running user cannot edit. The section says to use user mode when a handler must respect the user's permissions.
  • CONTRIBUTING.md states the same rule for the sample and the README examples.
  • The sample README describes the new trigger, handler, and test.
  • The hand-written sample page of the documentation site, doc-assets/files/sampletriggerhandlerhome.html, shows the new trigger and handler. It showed a without sharing handler that called a method that does not exist. The published site changes when the documentation is next regenerated.

Behavior notes

  • The sample is not a package directory, so the Deploy to Salesforce button and a deploy of force-app do not install it. Only an org that deploys sample-handler gets the new trigger. It still fires in all 7 contexts, as before.
  • The DevSecOps Java rule FlagSystemMode reports system-mode statements. This project does not run it yet. It comes in a separate pull request, which also decides how to treat the sample's deliberate system mode.

Test plan

  • Scratch org at API 67.0: 40 of 40 local tests pass, with 100 percent coverage and no uncovered lines on TriggerHandler, AccountSampleTriggerHandler, and AccountSampleTrigger.
  • With the self-bypass removed from the handler, childUpdateDoesNotRunHandlerAgain fails, so the test catches a handler that runs again for the child update. The original handler was then deployed again.
  • Code Analyzer with the CI rule selector reports 0 findings in the 3 sample files, against 5 on main, and 0 priority 1 or 2 findings in the project.
  • The Prettier check passes.
  • The README examples were not compiled again: they changed only from user mode to system mode.

BEGIN_NESTED_COMMIT
refactor(sample): rewrite the sample to show the framework in use

The sample trigger has no logic and lists all 7 contexts, and the handler shows a self-bypass around a child update, a loop limit that a bulk update does not reach, andFinally, and the old records, with system mode on its query and DML statement and 1 test per behavior.
END_NESTED_COMMIT

BEGIN_NESTED_COMMIT
docs(readme): use system mode in the handler examples

The README examples name WITH SYSTEM_MODE and AccessLevel.SYSTEM_MODE, a new Data access section explains why and when to use user mode instead, and CONTRIBUTING states the same rule.
END_NESTED_COMMIT

BEGIN_NESTED_COMMIT
docs(readme): list all 7 contexts in every trigger example

The README tells readers to list all 7 contexts so that a trigger is written once and never edited again, and to leave out only the contexts that an object does not support, instead of listing only the contexts a handler overrides.
END_NESTED_COMMIT

BEGIN_NESTED_COMMIT
docs(sample): describe the new sample in its README and docs page

The sample README and the sample page of the documentation site show the new trigger and handler, which replaces a page that showed a without sharing handler and a method that does not exist.
END_NESTED_COMMIT

Sorry, something went wrong.

Uh oh!

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

All reactions
Claude AI @claude
refactor(sample): rewrite the sample to show the framework in use
a4cb89a
The sample trigger lists only the 3 contexts the handler overrides and has no logic. The handler normalizes new and changed Account names, copies a changed phone number to child Accounts with a self-bypass that a finally block clears, sets a loop limit that a bulk update does not reach, and records each finished operation in andFinally(). Every query and DML statement names SYSTEM_MODE. The test class proves each behavior with real DML, 1 test per behavior.

The README examples use SYSTEM_MODE, and a new Data access section says when to choose USER_MODE instead. The sample README, the CONTRIBUTING code standard, and the sample page of the documentation site match the new sample.

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

codecov Bot commented Oct 29, 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 (d3c42d2) to head (abf6615).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #366   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          214       233   +19     
=========================================
+ Hits           214       233   +19     
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): list all 7 contexts in every trigger example
abf6615
The sample trigger lists all 7 contexts again, so that it is written once and never edited when the handler gets a new override. The README now tells readers to do the same and to leave out only the contexts that an object does not support, and all 4 README trigger examples list the 7 contexts. The sample test checks that andFinally() runs after all 7 contexts, delete and undelete included.

Co-Authored-By: Claude <[email protected]>
@dschach
dschach merged commit 149de0c into main Oct 29, 2026
6 checks passed

Uh oh!

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

@dschach
dschach deleted the refactor/sample-handler branch October 29, 2026 22:38
@github-actions github-actions Bot mentioned this pull request Oct 29, 2026
chore(main): release 1.4.2 #364
Merged
dschach pushed a commit that referenced this pull request Oct 30, 2026
@github-actions
chore(main): release 1.4.2 (#364)
57f57b2
🤖 I have created a release *beep* *boop*
---


##
[1.4.2](v1.4.1...v1.4.2)
(2026-10-30)


### Tests

* **handler:** Assert through the public API with correct messages
([5359db1](5359db1))
* **handler:** Cover the bypass clears and run outside a trigger
([5359db1](5359db1))
* **handler:** Prove that bypasses and the loop limit stop andFinally
([5359db1](5359db1))
* **handler:** Rewrite the TriggerHandler tests with 1 test per behavior
([#365](#365))
([5359db1](5359db1))
* **handler:** Split the handler tests into 1 test per behavior
([5359db1](5359db1))


### Miscellaneous Chores

* **hooks:** Strip the config machine paths in the staged file
([65276b0](65276b0))
* **pmd:** Add the DevSecOps Java rules to Code Analyzer
([73b70a4](73b70a4))
* **pmd:** Add the DevSecOps Java rules to Code Analyzer
([#367](#367))
([73b70a4](73b70a4))
* **pmd:** Regenerate code-analyzer.yml and correct the ruleset notes
([65276b0](65276b0))
* **pmd:** Turn off a rule and keep machine paths out of the config
([#369](#369))
([65276b0](65276b0))
* **pmd:** Turn off AvoidTrivialPropertyGetters
([65276b0](65276b0))
* **sample:** Suppress FlagSystemMode where system mode is deliberate
([73b70a4](73b70a4))
* **scripts:** Write the Code Analyzer results to the sfca folder
([73b70a4](73b70a4))


### Code Refactoring

* **sample:** Rewrite the sample to show the framework in use
([149de0c](149de0c))
* **sample:** Rewrite the sample to show the framework in use
([#366](#366))
([149de0c](149de0c))


### Documentation

* **contributing:** Explain how to mark a deliberate system mode
([73b70a4](73b70a4))
* **readme:** List all 7 contexts in every trigger example
([149de0c](149de0c))
* **readme:** Use system mode in the handler examples
([149de0c](149de0c))
* **sample:** Describe the new sample in its README and docs page
([149de0c](149de0c))


### Continuous Integration

* **apex-tests:** Delete the scratch org after a cancelled run
([0890448](0890448))
* **ci:** Give each push to main its own concurrency group
([0890448](0890448))
* **dependabot:** Run the update workflow once per pull request at a
time
([0890448](0890448))
* **release-please:** Queue runs instead of running them at once
([0890448](0890448))
* **workflows:** Add concurrency groups so runs do not cancel each other
([#363](#363))
([0890448](0890448))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.