scc-universal 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/.claude-plugin/plugin.json +44 -0
  2. package/.cursor/agents/deep-researcher.md +142 -0
  3. package/.cursor/agents/doc-updater.md +219 -0
  4. package/.cursor/agents/eval-runner.md +335 -0
  5. package/.cursor/agents/learning-engine.md +210 -0
  6. package/.cursor/agents/loop-operator.md +245 -0
  7. package/.cursor/agents/refactor-cleaner.md +119 -0
  8. package/.cursor/agents/sf-admin-agent.md +127 -0
  9. package/.cursor/agents/sf-agentforce-agent.md +126 -0
  10. package/.cursor/agents/sf-apex-agent.md +117 -0
  11. package/.cursor/agents/sf-architect.md +426 -0
  12. package/.cursor/agents/sf-aura-reviewer.md +369 -0
  13. package/.cursor/agents/sf-bugfix-agent.md +101 -0
  14. package/.cursor/agents/sf-flow-agent.md +155 -0
  15. package/.cursor/agents/sf-integration-agent.md +141 -0
  16. package/.cursor/agents/sf-lwc-agent.md +123 -0
  17. package/.cursor/agents/sf-review-agent.md +357 -0
  18. package/.cursor/agents/sf-visualforce-reviewer.md +465 -0
  19. package/.cursor/hooks/adapter.js +81 -0
  20. package/.cursor/hooks/after-file-edit.js +26 -0
  21. package/.cursor/hooks/after-mcp-execution.js +12 -0
  22. package/.cursor/hooks/after-shell-execution.js +30 -0
  23. package/.cursor/hooks/after-tab-file-edit.js +12 -0
  24. package/.cursor/hooks/before-mcp-execution.js +11 -0
  25. package/.cursor/hooks/before-read-file.js +13 -0
  26. package/.cursor/hooks/before-shell-execution.js +29 -0
  27. package/.cursor/hooks/before-submit-prompt.js +23 -0
  28. package/.cursor/hooks/pre-compact.js +7 -0
  29. package/.cursor/hooks/session-end.js +10 -0
  30. package/.cursor/hooks/session-start.js +10 -0
  31. package/.cursor/hooks/stop.js +18 -0
  32. package/.cursor/hooks/subagent-start.js +10 -0
  33. package/.cursor/hooks/subagent-stop.js +10 -0
  34. package/.cursor/hooks.json +107 -0
  35. package/.cursor/skills/aside/SKILL.md +115 -0
  36. package/.cursor/skills/checkpoint/SKILL.md +50 -0
  37. package/.cursor/skills/configure-scc/SKILL.md +160 -0
  38. package/.cursor/skills/continuous-agent-loop/SKILL.md +260 -0
  39. package/.cursor/skills/mcp-server-patterns/SKILL.md +142 -0
  40. package/.cursor/skills/model-route/SKILL.md +81 -0
  41. package/.cursor/skills/prompt-optimizer/SKILL.md +366 -0
  42. package/.cursor/skills/refactor-clean/SKILL.md +133 -0
  43. package/.cursor/skills/resume-session/SKILL.md +111 -0
  44. package/.cursor/skills/save-session/SKILL.md +183 -0
  45. package/.cursor/skills/search-first/SKILL.md +140 -0
  46. package/.cursor/skills/security-scan/SKILL.md +142 -0
  47. package/.cursor/skills/sessions/SKILL.md +124 -0
  48. package/.cursor/skills/sf-agentforce-development/SKILL.md +449 -0
  49. package/.cursor/skills/sf-apex-async-patterns/SKILL.md +324 -0
  50. package/.cursor/skills/sf-apex-best-practices/SKILL.md +421 -0
  51. package/.cursor/skills/sf-apex-constraints/SKILL.md +79 -0
  52. package/.cursor/skills/sf-apex-cursor/SKILL.md +336 -0
  53. package/.cursor/skills/sf-apex-enterprise-patterns/SKILL.md +344 -0
  54. package/.cursor/skills/sf-apex-testing/SKILL.md +407 -0
  55. package/.cursor/skills/sf-api-design/SKILL.md +237 -0
  56. package/.cursor/skills/sf-approval-processes/SKILL.md +312 -0
  57. package/.cursor/skills/sf-aura-development/SKILL.md +260 -0
  58. package/.cursor/skills/sf-build-fix/SKILL.md +120 -0
  59. package/.cursor/skills/sf-data-modeling/SKILL.md +274 -0
  60. package/.cursor/skills/sf-debugging/SKILL.md +362 -0
  61. package/.cursor/skills/sf-deployment/SKILL.md +291 -0
  62. package/.cursor/skills/sf-deployment-constraints/SKILL.md +153 -0
  63. package/.cursor/skills/sf-devops-ci-cd/SKILL.md +322 -0
  64. package/.cursor/skills/sf-docs-lookup/SKILL.md +100 -0
  65. package/.cursor/skills/sf-e2e-testing/SKILL.md +321 -0
  66. package/.cursor/skills/sf-experience-cloud/SKILL.md +248 -0
  67. package/.cursor/skills/sf-flow-development/SKILL.md +376 -0
  68. package/.cursor/skills/sf-governor-limits/SKILL.md +319 -0
  69. package/.cursor/skills/sf-harness-audit/SKILL.md +139 -0
  70. package/.cursor/skills/sf-help/SKILL.md +156 -0
  71. package/.cursor/skills/sf-integration/SKILL.md +479 -0
  72. package/.cursor/skills/sf-lwc-constraints/SKILL.md +128 -0
  73. package/.cursor/skills/sf-lwc-development/SKILL.md +302 -0
  74. package/.cursor/skills/sf-lwc-testing/SKILL.md +387 -0
  75. package/.cursor/skills/sf-metadata-management/SKILL.md +285 -0
  76. package/.cursor/skills/sf-platform-events-cdc/SKILL.md +372 -0
  77. package/.cursor/skills/sf-quickstart/SKILL.md +170 -0
  78. package/.cursor/skills/sf-security/SKILL.md +330 -0
  79. package/.cursor/skills/sf-security-constraints/SKILL.md +125 -0
  80. package/.cursor/skills/sf-soql-constraints/SKILL.md +129 -0
  81. package/.cursor/skills/sf-soql-optimization/SKILL.md +353 -0
  82. package/.cursor/skills/sf-tdd-workflow/SKILL.md +332 -0
  83. package/.cursor/skills/sf-testing-constraints/SKILL.md +198 -0
  84. package/.cursor/skills/sf-trigger-constraints/SKILL.md +88 -0
  85. package/.cursor/skills/sf-trigger-frameworks/SKILL.md +343 -0
  86. package/.cursor/skills/sf-visualforce-development/SKILL.md +259 -0
  87. package/.cursor/skills/strategic-compact/SKILL.md +205 -0
  88. package/.cursor/skills/update-docs/SKILL.md +162 -0
  89. package/.cursor/skills/update-platform-docs/SKILL.md +86 -0
  90. package/.cursor-plugin/plugin.json +26 -0
  91. package/LICENSE +21 -0
  92. package/README.md +522 -0
  93. package/agents/deep-researcher.md +145 -0
  94. package/agents/doc-updater.md +222 -0
  95. package/agents/eval-runner.md +340 -0
  96. package/agents/learning-engine.md +211 -0
  97. package/agents/loop-operator.md +247 -0
  98. package/agents/refactor-cleaner.md +122 -0
  99. package/agents/sf-admin-agent.md +131 -0
  100. package/agents/sf-agentforce-agent.md +132 -0
  101. package/agents/sf-apex-agent.md +124 -0
  102. package/agents/sf-architect.md +435 -0
  103. package/agents/sf-aura-reviewer.md +372 -0
  104. package/agents/sf-bugfix-agent.md +105 -0
  105. package/agents/sf-flow-agent.md +159 -0
  106. package/agents/sf-integration-agent.md +146 -0
  107. package/agents/sf-lwc-agent.md +127 -0
  108. package/agents/sf-review-agent.md +366 -0
  109. package/agents/sf-visualforce-reviewer.md +468 -0
  110. package/assets/logo.svg +18 -0
  111. package/docs/ARCHITECTURE.md +133 -0
  112. package/docs/authoring-guide.md +373 -0
  113. package/docs/hook-development.md +578 -0
  114. package/docs/token-optimization.md +139 -0
  115. package/docs/workflow-examples.md +645 -0
  116. package/examples/agentforce-action/README.md +227 -0
  117. package/examples/apex-trigger-handler/README.md +114 -0
  118. package/examples/devops-pipeline/README.md +325 -0
  119. package/examples/flow-automation/README.md +188 -0
  120. package/examples/integration-pattern/README.md +416 -0
  121. package/examples/lwc-component/README.md +180 -0
  122. package/examples/platform-events/README.md +492 -0
  123. package/examples/scratch-org-setup/README.md +138 -0
  124. package/examples/security-audit/README.md +244 -0
  125. package/examples/visualforce-migration/README.md +314 -0
  126. package/hooks/hooks.json +338 -0
  127. package/hooks/memory-persistence/README.md +73 -0
  128. package/manifests/install-modules.json +217 -0
  129. package/manifests/install-profiles.json +17 -0
  130. package/mcp-configs/mcp-servers.json +19 -0
  131. package/package.json +89 -0
  132. package/schemas/hooks.schema.json +123 -0
  133. package/schemas/install-modules.schema.json +76 -0
  134. package/schemas/install-profiles.schema.json +28 -0
  135. package/schemas/install-state.schema.json +73 -0
  136. package/schemas/package-manager.schema.json +18 -0
  137. package/schemas/plugin.schema.json +112 -0
  138. package/schemas/scc-install-config.schema.json +29 -0
  139. package/schemas/state-store.schema.json +111 -0
  140. package/scripts/cli/install-apply.js +170 -0
  141. package/scripts/cli/uninstall.js +193 -0
  142. package/scripts/hooks/check-console-log.js +101 -0
  143. package/scripts/hooks/check-hook-enabled.js +17 -0
  144. package/scripts/hooks/check-platform-docs-age.js +48 -0
  145. package/scripts/hooks/cost-tracker.js +78 -0
  146. package/scripts/hooks/doc-file-warning.js +63 -0
  147. package/scripts/hooks/evaluate-session.js +98 -0
  148. package/scripts/hooks/governor-check.js +220 -0
  149. package/scripts/hooks/learning-observe.sh +206 -0
  150. package/scripts/hooks/mcp-health-check.js +588 -0
  151. package/scripts/hooks/post-bash-build-complete.js +34 -0
  152. package/scripts/hooks/post-bash-pr-created.js +43 -0
  153. package/scripts/hooks/post-edit-console-warn.js +61 -0
  154. package/scripts/hooks/post-edit-format.js +79 -0
  155. package/scripts/hooks/post-edit-typecheck.js +98 -0
  156. package/scripts/hooks/post-write.js +168 -0
  157. package/scripts/hooks/pre-bash-git-push-reminder.js +35 -0
  158. package/scripts/hooks/pre-bash-tmux-reminder.js +47 -0
  159. package/scripts/hooks/pre-compact.js +51 -0
  160. package/scripts/hooks/pre-tool-use.js +163 -0
  161. package/scripts/hooks/pre-write-doc-warn.js +9 -0
  162. package/scripts/hooks/quality-gate.js +251 -0
  163. package/scripts/hooks/run-with-flags-shell.sh +32 -0
  164. package/scripts/hooks/run-with-flags.js +135 -0
  165. package/scripts/hooks/session-end-marker.js +29 -0
  166. package/scripts/hooks/session-end.js +311 -0
  167. package/scripts/hooks/session-start.js +202 -0
  168. package/scripts/hooks/sfdx-scanner-check.js +142 -0
  169. package/scripts/hooks/sfdx-validate.js +119 -0
  170. package/scripts/hooks/stop-hook.js +170 -0
  171. package/scripts/hooks/suggest-compact.js +67 -0
  172. package/scripts/lib/agent-adapter.js +82 -0
  173. package/scripts/lib/apex-analysis.js +194 -0
  174. package/scripts/lib/hook-flags.js +74 -0
  175. package/scripts/lib/install-config.js +73 -0
  176. package/scripts/lib/install-executor.js +363 -0
  177. package/scripts/lib/install-state.js +121 -0
  178. package/scripts/lib/orchestration-session.js +299 -0
  179. package/scripts/lib/package-manager.js +124 -0
  180. package/scripts/lib/project-detect.js +228 -0
  181. package/scripts/lib/schema-validator.js +190 -0
  182. package/scripts/lib/skill-adapter.js +100 -0
  183. package/scripts/lib/state-store.js +376 -0
  184. package/scripts/lib/tmux-worktree-orchestrator.js +598 -0
  185. package/scripts/lib/utils.js +313 -0
  186. package/scripts/scc.js +164 -0
  187. package/skills/_reference/AGENTFORCE_PATTERNS.md +112 -0
  188. package/skills/_reference/APEX_CURSOR.md +159 -0
  189. package/skills/_reference/API_VERSIONS.md +78 -0
  190. package/skills/_reference/APPROVAL_PROCESSES.md +105 -0
  191. package/skills/_reference/ASYNC_PATTERNS.md +163 -0
  192. package/skills/_reference/AURA_COMPONENTS.md +146 -0
  193. package/skills/_reference/DATA_MIGRATION_PATTERNS.md +151 -0
  194. package/skills/_reference/DATA_MODELING.md +124 -0
  195. package/skills/_reference/DEBUGGING_TOOLS.md +140 -0
  196. package/skills/_reference/DEPLOYMENT_CHECKLIST.md +87 -0
  197. package/skills/_reference/DEPRECATIONS.md +79 -0
  198. package/skills/_reference/DOCKER_CI_PATTERNS.md +138 -0
  199. package/skills/_reference/ENTERPRISE_PATTERNS.md +122 -0
  200. package/skills/_reference/EXPERIENCE_CLOUD.md +143 -0
  201. package/skills/_reference/FLOW_PATTERNS.md +113 -0
  202. package/skills/_reference/GOVERNOR_LIMITS.md +77 -0
  203. package/skills/_reference/INTEGRATION_PATTERNS.md +105 -0
  204. package/skills/_reference/LWC_PATTERNS.md +79 -0
  205. package/skills/_reference/METADATA_TYPES.md +115 -0
  206. package/skills/_reference/NAMING_CONVENTIONS.md +84 -0
  207. package/skills/_reference/PACKAGE_DEVELOPMENT.md +150 -0
  208. package/skills/_reference/PLATFORM_EVENTS.md +121 -0
  209. package/skills/_reference/REPORTING_API.md +143 -0
  210. package/skills/_reference/SCRATCH_ORG_PATTERNS.md +126 -0
  211. package/skills/_reference/SECURITY_PATTERNS.md +127 -0
  212. package/skills/_reference/SHARING_MODEL.md +120 -0
  213. package/skills/_reference/SOQL_PATTERNS.md +119 -0
  214. package/skills/_reference/TESTING_STANDARDS.md +96 -0
  215. package/skills/_reference/TRIGGER_PATTERNS.md +114 -0
  216. package/skills/_reference/VISUALFORCE_PATTERNS.md +121 -0
  217. package/skills/aside/SKILL.md +118 -0
  218. package/skills/checkpoint/SKILL.md +53 -0
  219. package/skills/configure-scc/SKILL.md +163 -0
  220. package/skills/continuous-agent-loop/SKILL.md +264 -0
  221. package/skills/mcp-server-patterns/SKILL.md +146 -0
  222. package/skills/model-route/SKILL.md +84 -0
  223. package/skills/prompt-optimizer/SKILL.md +369 -0
  224. package/skills/refactor-clean/SKILL.md +136 -0
  225. package/skills/resume-session/SKILL.md +114 -0
  226. package/skills/save-session/SKILL.md +186 -0
  227. package/skills/search-first/SKILL.md +144 -0
  228. package/skills/security-scan/SKILL.md +146 -0
  229. package/skills/sessions/SKILL.md +127 -0
  230. package/skills/sf-agentforce-development/SKILL.md +450 -0
  231. package/skills/sf-apex-async-patterns/SKILL.md +326 -0
  232. package/skills/sf-apex-best-practices/SKILL.md +425 -0
  233. package/skills/sf-apex-constraints/SKILL.md +81 -0
  234. package/skills/sf-apex-cursor/SKILL.md +338 -0
  235. package/skills/sf-apex-enterprise-patterns/SKILL.md +348 -0
  236. package/skills/sf-apex-testing/SKILL.md +409 -0
  237. package/skills/sf-api-design/SKILL.md +238 -0
  238. package/skills/sf-approval-processes/SKILL.md +315 -0
  239. package/skills/sf-aura-development/SKILL.md +263 -0
  240. package/skills/sf-build-fix/SKILL.md +121 -0
  241. package/skills/sf-data-modeling/SKILL.md +278 -0
  242. package/skills/sf-debugging/SKILL.md +363 -0
  243. package/skills/sf-deployment/SKILL.md +295 -0
  244. package/skills/sf-deployment-constraints/SKILL.md +155 -0
  245. package/skills/sf-devops-ci-cd/SKILL.md +325 -0
  246. package/skills/sf-docs-lookup/SKILL.md +103 -0
  247. package/skills/sf-e2e-testing/SKILL.md +324 -0
  248. package/skills/sf-experience-cloud/SKILL.md +249 -0
  249. package/skills/sf-flow-development/SKILL.md +377 -0
  250. package/skills/sf-governor-limits/SKILL.md +323 -0
  251. package/skills/sf-harness-audit/SKILL.md +142 -0
  252. package/skills/sf-help/SKILL.md +159 -0
  253. package/skills/sf-integration/SKILL.md +483 -0
  254. package/skills/sf-lwc-constraints/SKILL.md +130 -0
  255. package/skills/sf-lwc-development/SKILL.md +303 -0
  256. package/skills/sf-lwc-testing/SKILL.md +388 -0
  257. package/skills/sf-metadata-management/SKILL.md +288 -0
  258. package/skills/sf-platform-events-cdc/SKILL.md +375 -0
  259. package/skills/sf-quickstart/SKILL.md +173 -0
  260. package/skills/sf-security/SKILL.md +334 -0
  261. package/skills/sf-security-constraints/SKILL.md +127 -0
  262. package/skills/sf-soql-constraints/SKILL.md +131 -0
  263. package/skills/sf-soql-optimization/SKILL.md +354 -0
  264. package/skills/sf-tdd-workflow/SKILL.md +336 -0
  265. package/skills/sf-testing-constraints/SKILL.md +200 -0
  266. package/skills/sf-trigger-constraints/SKILL.md +90 -0
  267. package/skills/sf-trigger-frameworks/SKILL.md +347 -0
  268. package/skills/sf-visualforce-development/SKILL.md +260 -0
  269. package/skills/strategic-compact/SKILL.md +208 -0
  270. package/skills/update-docs/SKILL.md +165 -0
  271. package/skills/update-platform-docs/SKILL.md +90 -0
@@ -0,0 +1,343 @@
1
+ ---
2
+ name: sf-trigger-frameworks
3
+ description: >-
4
+ Salesforce Apex trigger framework patterns — TriggerHandler, FFLIB Domain, TDTM, bypass and recursion control. Use when adopting or refactoring triggers.
5
+ disable-model-invocation: true
6
+ ---
7
+
8
+ # Trigger Frameworks
9
+
10
+ Implementation guidance for trigger framework patterns. Constraint rules (one-trigger-per-object, no-logic-in-trigger-body, etc.) live in `sf-trigger-constraints`. This skill covers the _how_ — framework selection, base class implementation, bypass mechanisms, and recursion prevention.
11
+
12
+ Reference: @../_reference/TRIGGER_PATTERNS.md
13
+
14
+ ---
15
+
16
+ ## When to Use
17
+
18
+ - When evaluating which trigger framework pattern to adopt for a new project
19
+ - When refactoring bare trigger logic to a handler-based architecture
20
+ - When a trigger is firing recursively and causing unexpected DML or loop errors
21
+ - When you need a bypass mechanism to suppress triggers during data migrations
22
+ - When multiple triggers exist on the same SObject and need to be consolidated
23
+ - When comparing Pragmatic TriggerHandler vs FFLIB Domain Layer
24
+
25
+ ---
26
+
27
+ ## The Pragmatic TriggerHandler Pattern
28
+
29
+ A clean, dependency-free framework. The base class provides context-aware routing, bypass mechanism, and recursion control.
30
+
31
+ ### TriggerHandler Base Class
32
+
33
+ ```apex
34
+ public virtual class TriggerHandler {
35
+
36
+ // Bypass Registry
37
+ private static Set<String> bypassedHandlers = new Set<String>();
38
+
39
+ // Recursion Control
40
+ private static Map<String, Integer> depthMap = new Map<String, Integer>();
41
+ private static final Integer MAX_DEPTH = 2;
42
+
43
+ // Context Properties
44
+ @TestVisible protected Boolean isBefore { get { return Trigger.isBefore; } }
45
+ @TestVisible protected Boolean isAfter { get { return Trigger.isAfter; } }
46
+ @TestVisible protected Boolean isInsert { get { return Trigger.isInsert; } }
47
+ @TestVisible protected Boolean isUpdate { get { return Trigger.isUpdate; } }
48
+ @TestVisible protected Boolean isDelete { get { return Trigger.isDelete; } }
49
+ @TestVisible protected Boolean isUndelete { get { return Trigger.isUndelete; } }
50
+
51
+ protected List<SObject> newList { get { return Trigger.new; } }
52
+ protected Map<Id, SObject> newMap { get { return Trigger.newMap; } }
53
+ protected List<SObject> oldList { get { return Trigger.old; } }
54
+ protected Map<Id, SObject> oldMap { get { return Trigger.oldMap; } }
55
+
56
+ public void run() {
57
+ String handlerName = getHandlerName();
58
+ if (isBypassed(handlerName)) return;
59
+ if (exceedsMaxDepth(handlerName)) return;
60
+
61
+ incrementDepth(handlerName);
62
+ try { dispatch(); }
63
+ finally { decrementDepth(handlerName); }
64
+ }
65
+
66
+ private void dispatch() {
67
+ if (isBefore) {
68
+ if (isInsert) onBeforeInsert();
69
+ if (isUpdate) onBeforeUpdate();
70
+ if (isDelete) onBeforeDelete();
71
+ } else if (isAfter) {
72
+ if (isInsert) onAfterInsert();
73
+ if (isUpdate) onAfterUpdate();
74
+ if (isDelete) onAfterDelete();
75
+ if (isUndelete) onAfterUndelete();
76
+ }
77
+ }
78
+
79
+ // Virtual Methods — Override in Concrete Handlers
80
+ @TestVisible protected virtual void onBeforeInsert() {}
81
+ @TestVisible protected virtual void onBeforeUpdate() {}
82
+ @TestVisible protected virtual void onBeforeDelete() {}
83
+ @TestVisible protected virtual void onAfterInsert() {}
84
+ @TestVisible protected virtual void onAfterUpdate() {}
85
+ @TestVisible protected virtual void onAfterDelete() {}
86
+ @TestVisible protected virtual void onAfterUndelete() {}
87
+
88
+ // Bypass API
89
+ public static void bypass(String handlerName) { bypassedHandlers.add(handlerName); }
90
+ public static void clearBypass(String handlerName) { bypassedHandlers.remove(handlerName); }
91
+ public static void clearAllBypasses() { bypassedHandlers.clear(); }
92
+ public static Boolean isBypassed(String handlerName) { return bypassedHandlers.contains(handlerName); }
93
+
94
+ // Private Helpers
95
+ private String getHandlerName() { return String.valueOf(this).split(':')[0]; }
96
+ private Boolean exceedsMaxDepth(String h) { return getDepth(h) >= MAX_DEPTH; }
97
+ private Integer getDepth(String h) { return depthMap.containsKey(h) ? depthMap.get(h) : 0; }
98
+ private void incrementDepth(String h) { depthMap.put(h, getDepth(h) + 1); }
99
+ private void decrementDepth(String h) { Integer c = getDepth(h); if (c > 0) depthMap.put(h, c - 1); }
100
+ }
101
+ ```
102
+
103
+ ### Concrete Handler
104
+
105
+ ```apex
106
+ public class AccountTriggerHandler extends TriggerHandler {
107
+
108
+ private List<Account> newAccounts;
109
+ private Map<Id, Account> oldAccountMap;
110
+
111
+ public AccountTriggerHandler() {
112
+ newAccounts = (List<Account>) newList;
113
+ oldAccountMap = (Map<Id, Account>) oldMap;
114
+ }
115
+
116
+ override protected void onBeforeInsert() {
117
+ AccountDefaults.setDefaults(newAccounts);
118
+ AccountValidator.validateForInsert(newAccounts);
119
+ }
120
+
121
+ override protected void onBeforeUpdate() {
122
+ AccountValidator.validateForUpdate(newAccounts, oldAccountMap);
123
+ }
124
+
125
+ override protected void onAfterInsert() {
126
+ AccountOpportunityCreator.createDefaultOpportunities(newAccounts);
127
+ }
128
+
129
+ override protected void onAfterUpdate() {
130
+ AccountRelatedUpdater.syncContactOwnership(
131
+ (Map<Id, Account>) newMap, oldAccountMap
132
+ );
133
+ }
134
+ }
135
+ ```
136
+
137
+ ### Trigger File
138
+
139
+ ```apex
140
+ trigger AccountTrigger on Account (
141
+ before insert, before update, before delete,
142
+ after insert, after update, after delete, after undelete
143
+ ) {
144
+ new AccountTriggerHandler().run();
145
+ }
146
+ ```
147
+
148
+ ---
149
+
150
+ ## FFLIB Domain Layer
151
+
152
+ For orgs using the FFLIB Apex Commons library, the Domain layer is the preferred trigger handling mechanism.
153
+
154
+ ```apex
155
+ public with sharing class Accounts extends fflib_SObjectDomain {
156
+
157
+ public Accounts(List<Account> sObjectList) {
158
+ super(sObjectList);
159
+ Configuration.disableTriggerCRUDSecurity();
160
+ }
161
+
162
+ public override void onBeforeInsert() {
163
+ setDefaultCustomerTier();
164
+ }
165
+
166
+ public override void onBeforeUpdate(Map<Id, SObject> existingRecords) {
167
+ preventPremiumTierDowngrade((Map<Id, Account>) existingRecords);
168
+ }
169
+
170
+ public class Constructor implements fflib_SObjectDomain.IConstructable {
171
+ public fflib_SObjectDomain construct(List<SObject> sObjectList) {
172
+ return new Accounts(sObjectList);
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ > `Configuration.disableTriggerCRUDSecurity()` is needed because trigger handlers operate on records already committed by the platform. Do NOT disable CRUD security in Service or Controller layers.
179
+
180
+ ---
181
+
182
+ ## TDTM (Table-Driven Trigger Management)
183
+
184
+ Registers handlers in Custom Metadata (`Trigger_Handler__mdt`), enabling enable/disable without code deployment.
185
+
186
+ **CMDT fields:** `Object_Name__c`, `Handler_Class__c`, `Trigger_Event__c`, `Is_Active__c`, `Execution_Order__c`
187
+
188
+ ```apex
189
+ public class TDTMDispatcher {
190
+
191
+ private static Map<String, List<Trigger_Handler__mdt>> handlerCache =
192
+ new Map<String, List<Trigger_Handler__mdt>>();
193
+
194
+ public static void run(
195
+ String objectName, String triggerEvent,
196
+ List<SObject> newList, List<SObject> oldList,
197
+ Map<Id, SObject> newMap, Map<Id, SObject> oldMap
198
+ ) {
199
+ String cacheKey = objectName + ':' + triggerEvent;
200
+ List<Trigger_Handler__mdt> activeHandlers;
201
+ if (handlerCache.containsKey(cacheKey)) {
202
+ activeHandlers = handlerCache.get(cacheKey);
203
+ } else {
204
+ activeHandlers = [
205
+ SELECT Handler_Class__c, Execution_Order__c
206
+ FROM Trigger_Handler__mdt
207
+ WHERE Object_Name__c = :objectName
208
+ AND Trigger_Event__c = :triggerEvent
209
+ AND Is_Active__c = true
210
+ ORDER BY Execution_Order__c ASC
211
+ ];
212
+ handlerCache.put(cacheKey, activeHandlers);
213
+ }
214
+
215
+ for (Trigger_Handler__mdt cfg : activeHandlers) {
216
+ Type handlerType = Type.forName(cfg.Handler_Class__c);
217
+ if (handlerType == null) continue;
218
+ ITriggerHandler handler = (ITriggerHandler) handlerType.newInstance();
219
+ handler.execute(newList, oldList, newMap, oldMap);
220
+ }
221
+ }
222
+
223
+ public interface ITriggerHandler {
224
+ void execute(List<SObject> newList, List<SObject> oldList,
225
+ Map<Id, SObject> newMap, Map<Id, SObject> oldMap);
226
+ }
227
+ }
228
+ ```
229
+
230
+ To disable a handler for data migration: set `Is_Active__c = false` in Setup.
231
+
232
+ ---
233
+
234
+ ## Bypass Mechanisms
235
+
236
+ ### Static Boolean (Simple)
237
+
238
+ ```apex
239
+ public class TriggerBypasses {
240
+ public static Boolean bypassAccountTrigger = false;
241
+ }
242
+
243
+ // Usage
244
+ TriggerBypasses.bypassAccountTrigger = true;
245
+ try {
246
+ insert accountsToMigrate;
247
+ } finally {
248
+ TriggerBypasses.bypassAccountTrigger = false;
249
+ }
250
+ ```
251
+
252
+ ### Framework-Level (`TriggerHandler.bypass()`)
253
+
254
+ ```apex
255
+ TriggerHandler.bypass('AccountTriggerHandler');
256
+ try {
257
+ insert accounts;
258
+ } finally {
259
+ TriggerHandler.clearBypass('AccountTriggerHandler');
260
+ }
261
+ ```
262
+
263
+ ### Custom Metadata Bypass (Declarative)
264
+
265
+ Map users/profiles to bypassed handlers via `Trigger_Bypass__mdt`. No code change needed.
266
+
267
+ ---
268
+
269
+ ## Recursion Prevention
270
+
271
+ ### Static Set of Processed IDs
272
+
273
+ ```apex
274
+ public class AccountTriggerHandler extends TriggerHandler {
275
+
276
+ @TestVisible
277
+ private static Set<Id> processedIds = new Set<Id>();
278
+
279
+ override protected void onAfterUpdate() {
280
+ List<Account> unprocessed = new List<Account>();
281
+ for (Account acc : (List<Account>) newList) {
282
+ if (!processedIds.contains(acc.Id)) {
283
+ processedIds.add(acc.Id);
284
+ unprocessed.add(acc);
285
+ }
286
+ }
287
+ if (!unprocessed.isEmpty()) {
288
+ AccountRelatedUpdater.syncContactOwnership(
289
+ new Map<Id, Account>(unprocessed), (Map<Id, Account>) oldMap
290
+ );
291
+ }
292
+ }
293
+ }
294
+ ```
295
+
296
+ > **Testing note:** Static variables reset between test methods. Within a single test method, they persist across multiple trigger executions.
297
+
298
+ ### Execution Depth Counter
299
+
300
+ Built into the TriggerHandler base class (MAX_DEPTH = 2). When a handler is called more than MAX_DEPTH times, execution is skipped. This prevents infinite recursion while allowing the first re-entry.
301
+
302
+ ---
303
+
304
+ ## Migration Guide: Bare Trigger to Framework
305
+
306
+ 1. Deploy `TriggerHandler.cls` base class
307
+ 2. Create handler class: `public class AccountTriggerHandler extends TriggerHandler {}`
308
+ 3. Refactor trigger: replace body with `new AccountTriggerHandler().run();`
309
+ 4. Move logic method by method into handler overrides or service classes
310
+ 5. Add bypass support via base class or Custom Metadata
311
+ 6. Delete old trigger files after consolidation
312
+
313
+ ---
314
+
315
+ ## Testing Trigger Frameworks
316
+
317
+ ```apex
318
+ @isTest
319
+ static void testBypassMechanism_noDefaultsSetWhenBypassed() {
320
+ TriggerHandler.bypass('AccountTriggerHandler');
321
+ Account acc = new Account(Name = 'Bypass Test', Type = 'Customer', Industry = 'Tech');
322
+
323
+ Test.startTest();
324
+ insert acc;
325
+ Test.stopTest();
326
+
327
+ TriggerHandler.clearBypass('AccountTriggerHandler');
328
+
329
+ Account result = [SELECT Customer_Tier__c FROM Account WHERE Id = :acc.Id];
330
+ System.assertEquals(null, result.Customer_Tier__c,
331
+ 'Tier should NOT be set when handler is bypassed');
332
+ }
333
+ ```
334
+
335
+ ---
336
+
337
+ ## Related
338
+
339
+ - **Agent**: `sf-architect` — For interactive, in-depth guidance
340
+
341
+ ### Guardrails
342
+
343
+ - `sf-trigger-constraints` — Enforces one-trigger-per-object, handler delegation, bulkification, and recursion prevention rules
@@ -0,0 +1,259 @@
1
+ ---
2
+ name: sf-visualforce-development
3
+ description: >-
4
+ Visualforce development — pages, controllers, extensions, ViewState, JS Remoting, LWC migration. Use when maintaining VF pages, building PDFs, or planning VF-to-LWC migration. Do NOT use for LWC, Aura, or Flow.
5
+ ---
6
+
7
+ # Visualforce Development
8
+
9
+ Visualforce is Salesforce's server-side rendering framework. While LWC is the modern standard, Visualforce remains heavily used for PDF generation, email templates, custom overrides, and legacy applications.
10
+
11
+ ## When to Use
12
+
13
+ - When maintaining or extending existing Visualforce pages in production
14
+ - When building PDF renderable pages (`renderAs="pdf"`) — LWC cannot do this
15
+ - When creating custom email templates with complex formatting
16
+ - When overriding standard buttons (New, Edit, View) with custom UIs
17
+ - When planning and executing migration from Visualforce to LWC
18
+ - When debugging ViewState issues or page performance problems
19
+
20
+ @../_reference/VISUALFORCE_PATTERNS.md
21
+
22
+ ---
23
+
24
+ ## Page Creation Procedure
25
+
26
+ ### Step 1 — Choose Controller Type
27
+
28
+ | Type | When to Use |
29
+ |------|------------|
30
+ | Standard Controller | Single-record CRUD without custom logic |
31
+ | Standard List Controller | List views with built-in pagination |
32
+ | Custom Controller | Full control over logic, data, navigation |
33
+ | Controller Extension | Add functionality to standard/custom controllers |
34
+
35
+ ### Step 2 — Create the Page
36
+
37
+ ```html
38
+ <apex:page standardController="Account"
39
+ extensions="AccountOverviewExtension"
40
+ lightningStylesheets="true"
41
+ docType="html-5.0"
42
+ title="Account Overview">
43
+ <apex:pageBlock title="Account Details">
44
+ <apex:pageBlockSection columns="2">
45
+ <apex:outputField value="{!Account.Name}" />
46
+ <apex:outputField value="{!Account.Industry}" />
47
+ </apex:pageBlockSection>
48
+ </apex:pageBlock>
49
+ </apex:page>
50
+ ```
51
+
52
+ ### Step 3 — Custom Controller (if needed)
53
+
54
+ ```apex
55
+ public with sharing class InvoiceController {
56
+ public List<Invoice__c> invoices { get; private set; }
57
+ public String searchTerm { get; set; }
58
+
59
+ public InvoiceController() {
60
+ searchTerm = '';
61
+ loadInvoices();
62
+ }
63
+
64
+ public PageReference search() {
65
+ loadInvoices();
66
+ return null; // Stay on same page
67
+ }
68
+
69
+ private void loadInvoices() {
70
+ String likeSearch = '%' + String.escapeSingleQuotes(searchTerm) + '%';
71
+ invoices = [
72
+ SELECT Id, Name, Amount__c, Status__c, CreatedDate
73
+ FROM Invoice__c WHERE Name LIKE :likeSearch
74
+ WITH USER_MODE ORDER BY CreatedDate DESC LIMIT 100
75
+ ];
76
+ }
77
+ }
78
+ ```
79
+
80
+ ### Step 4 — Controller Extension (if needed)
81
+
82
+ ```apex
83
+ public with sharing class AccountOverviewExtension {
84
+ private final Account account;
85
+
86
+ // Required constructor signature
87
+ public AccountOverviewExtension(ApexPages.StandardController stdController) {
88
+ if (!Test.isRunningTest()) {
89
+ stdController.addFields(new List<String>{ 'OwnerId', 'AnnualRevenue' });
90
+ }
91
+ this.account = (Account) stdController.getRecord();
92
+ }
93
+
94
+ public List<Contact> relatedContacts {
95
+ get {
96
+ if (relatedContacts == null) {
97
+ relatedContacts = [
98
+ SELECT Id, Name, Email, Phone
99
+ FROM Contact WHERE AccountId = :account.Id
100
+ WITH USER_MODE ORDER BY Name LIMIT 50
101
+ ];
102
+ }
103
+ return relatedContacts;
104
+ }
105
+ private set;
106
+ }
107
+ }
108
+ ```
109
+
110
+ ---
111
+
112
+ ## ViewState Management
113
+
114
+ ViewState is a hidden, encrypted form field that maintains page state across postbacks. **170KB limit** — exceeding it causes a runtime error.
115
+
116
+ ### The `transient` Keyword
117
+
118
+ Mark variables that do not need to survive postbacks as `transient`:
119
+
120
+ ```apex
121
+ public with sharing class ReportController {
122
+ // IN ViewState — needed across postbacks
123
+ public String selectedFilter { get; set; }
124
+ public Integer currentPage { get; set; }
125
+
126
+ // NOT in ViewState — recomputed on each request
127
+ transient public List<AggregateResult> reportData { get; private set; }
128
+ transient public Blob chartImage { get; private set; }
129
+ }
130
+ ```
131
+
132
+ ### Reduction Strategies
133
+
134
+ | Strategy | Impact |
135
+ |----------|--------|
136
+ | `transient` keyword on large/recomputable variables | High |
137
+ | `apex:outputPanel` + `reRender` (partial refresh) | Medium |
138
+ | Paginate large data sets | High |
139
+ | Use JavaScript Remoting (stateless) | High |
140
+ | Move read-only data outside `apex:form` | Medium |
141
+
142
+ ---
143
+
144
+ ## JavaScript Remoting
145
+
146
+ Stateless, high-performance Apex calls that bypass ViewState entirely.
147
+
148
+ ### Apex Method
149
+
150
+ ```apex
151
+ @RemoteAction
152
+ public static List<Account> findAccounts(String searchTerm) {
153
+ String safeTerm = '%' + String.escapeSingleQuotes(searchTerm) + '%';
154
+ return [
155
+ SELECT Id, Name, Industry FROM Account
156
+ WHERE Name LIKE :safeTerm WITH USER_MODE LIMIT 25
157
+ ];
158
+ }
159
+ ```
160
+
161
+ ### JavaScript Invocation
162
+
163
+ ```javascript
164
+ Visualforce.remoting.Manager.invokeAction(
165
+ '{!$RemoteAction.AccountSearchController.findAccounts}',
166
+ term,
167
+ function(result, event) {
168
+ if (event.status) {
169
+ renderResults(result);
170
+ } else {
171
+ console.error(event.message);
172
+ }
173
+ },
174
+ { escape: true, timeout: 30000 }
175
+ );
176
+ ```
177
+
178
+ Use `{!$RemoteAction.ClassName.methodName}` (namespace-safe). Set `escape: true` to prevent XSS.
179
+
180
+ ---
181
+
182
+ ## Partial Page Refresh
183
+
184
+ ```html
185
+ <apex:actionFunction name="refreshDashboard" action="{!refresh}"
186
+ reRender="dashPanel" status="loadingStatus" />
187
+
188
+ <apex:selectList value="{!selectedRegion}" size="1">
189
+ <apex:selectOptions value="{!regionOptions}" />
190
+ <apex:actionSupport event="onchange" action="{!filterByRegion}"
191
+ reRender="dashPanel" status="loadingStatus" />
192
+ </apex:selectList>
193
+
194
+ <apex:actionStatus id="loadingStatus">
195
+ <apex:facet name="start"><img src="/img/loading.gif" alt="Loading..." /></apex:facet>
196
+ </apex:actionStatus>
197
+ ```
198
+
199
+ ---
200
+
201
+ ## Migration to LWC
202
+
203
+ ### Decision Matrix
204
+
205
+ | Keep Visualforce | Migrate to LWC |
206
+ |-----------------|----------------|
207
+ | PDF generation (`renderAs="pdf"`) | High-traffic pages needing performance |
208
+ | Email templates | New feature development |
209
+ | Complex server-state wizards | Pages using Apex controller only |
210
+
211
+ ### Key VF-to-LWC Mappings
212
+
213
+ | Visualforce | LWC |
214
+ |------------|-----|
215
+ | `apex:pageBlockTable` | `lightning-datatable` |
216
+ | `apex:commandButton action="{!save}"` | `lightning-button onclick={handleSave}` + imperative Apex |
217
+ | `apex:inputField` | `lightning-input-field` (in `lightning-record-edit-form`) |
218
+ | JavaScript Remoting | `@wire` or imperative Apex import |
219
+ | `apex:actionSupport` | Standard DOM event handlers |
220
+ | `{!property}` merge fields | `{property}` template expressions |
221
+
222
+ ### Embedding LWC in Visualforce (Lightning Out)
223
+
224
+ For incremental migration, embed LWC inside existing VF pages:
225
+
226
+ ```html
227
+ <apex:includeLightning />
228
+ <div id="lwc-container"></div>
229
+ <script>
230
+ $Lightning.use("c:lwcOutApp", function() {
231
+ $Lightning.createComponent("c:accountDashboard",
232
+ { recordId: "{!Account.Id}" }, "lwc-container");
233
+ });
234
+ </script>
235
+ ```
236
+
237
+ ### Migration Checklist
238
+
239
+ 1. **Inventory** — list all VF pages, controllers, usage frequency
240
+ 2. **Categorize** — mark each page as Keep VF / Migrate / Retire
241
+ 3. **Dependencies** — map controller extensions, custom components, static resources
242
+ 4. **Security audit** — review XSS/injection issues before or during migration
243
+ 5. **Feature parity** — replicate all VF functionality in LWC
244
+ 6. **Test coverage** — write LWC Jest tests to match existing Apex test coverage
245
+ 7. **Incremental rollout** — use Lightning Out to embed LWC in VF during transition
246
+ 8. **Redirect** — update links, overrides, navigation to new LWC pages
247
+ 9. **Deprecate** — mark old VF pages as inactive, remove after validation
248
+
249
+ ---
250
+
251
+ ## Related
252
+
253
+ ### Guardrails
254
+
255
+ - **sf-security-constraints** — Enforced rules for XSS prevention, SOQL injection, CRUD/FLS enforcement
256
+
257
+ ### Agents
258
+
259
+ - **sf-visualforce-reviewer** — For interactive, in-depth Visualforce review guidance