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,285 @@
1
+ ---
2
+ name: sf-metadata-management
3
+ description: >-
4
+ Use when working with Salesforce metadata types, package.xml, or .forceignore. Source vs metadata format, retrieval, deployment, and org comparison.
5
+ ---
6
+
7
+ # Salesforce Metadata Management
8
+
9
+ Reference: @../_reference/METADATA_TYPES.md
10
+
11
+ ## When to Use
12
+
13
+ - Retrieving or deploying specific metadata types between Salesforce orgs
14
+ - Understanding the difference between source format (DX) and metadata API format
15
+ - Configuring `.forceignore` to control which files are tracked by SF CLI
16
+ - Managing profiles vs permission sets in source control and CI/CD workflows
17
+ - Comparing metadata between two orgs or handling org conflicts
18
+
19
+ ---
20
+
21
+ ## Source Format (DX) vs Metadata Format
22
+
23
+ ### Source Format (Salesforce DX -- what you have locally)
24
+
25
+ ```
26
+ force-app/
27
+ main/
28
+ default/
29
+ classes/
30
+ AccountService.cls
31
+ AccountService.cls-meta.xml
32
+ triggers/
33
+ AccountTrigger.trigger
34
+ AccountTrigger.trigger-meta.xml
35
+ lwc/
36
+ accountCard/
37
+ accountCard.js
38
+ accountCard.html
39
+ accountCard.css
40
+ accountCard.js-meta.xml
41
+ objects/
42
+ Account/
43
+ fields/
44
+ Status__c.field-meta.xml
45
+ recordTypes/
46
+ Enterprise.recordType-meta.xml
47
+ validationRules/
48
+ RequirePhone.validationRule-meta.xml
49
+ ```
50
+
51
+ ### Metadata Format (Metadata API / Change Sets)
52
+
53
+ ```
54
+ unpackaged/
55
+ classes/
56
+ AccountService.cls
57
+ AccountService.cls-meta.xml
58
+ objects/
59
+ Account.object <-- single file with ALL fields, validation rules, etc.
60
+ package.xml
61
+ ```
62
+
63
+ Key difference: in source format, each component has its own file. In metadata format, objects are a single monolithic XML file.
64
+
65
+ ```bash
66
+ # Convert metadata format to source format
67
+ sf project convert mdapi --root-dir unpackaged --output-dir force-app
68
+
69
+ # Convert source format to metadata format
70
+ sf project convert source --source-dir force-app --output-dir unpackaged
71
+ ```
72
+
73
+ ---
74
+
75
+ ## sfdx-project.json Explained
76
+
77
+ ```json
78
+ {
79
+ "packageDirectories": [
80
+ {
81
+ "path": "force-app",
82
+ "default": true,
83
+ "package": "MyApp",
84
+ "versionName": "ver 1.0",
85
+ "versionNumber": "1.0.0.NEXT",
86
+ "definitionFile": "config/project-scratch-def.json"
87
+ },
88
+ {
89
+ "path": "force-app-config",
90
+ "default": false
91
+ }
92
+ ],
93
+ "namespace": "",
94
+ "sourceApiVersion": "66.0",
95
+ "sfdcLoginUrl": "https://login.salesforce.com",
96
+ "pushPackageDirectoriesSequentially": false,
97
+ "packageAliases": {
98
+ "MyApp": "0Ho...",
99
+ "MyApp@1.0.0-1": "04t..."
100
+ }
101
+ }
102
+ ```
103
+
104
+ | Property | Purpose |
105
+ |-----------------------------|-------------------------------------------------------|
106
+ | `packageDirectories` | Directories containing Salesforce source |
107
+ | `path` | Relative path to source directory |
108
+ | `default` | Whether this is the default deploy target |
109
+ | `namespace` | Org namespace (empty string for most orgs) |
110
+ | `sourceApiVersion` | Metadata API version (update annually) |
111
+ | `pushPackageDirectoriesSequentially` | Deploy directories in order (for dependencies) |
112
+
113
+ ---
114
+
115
+ ## .forceignore
116
+
117
+ Controls which files SF CLI ignores during push/pull/deploy operations. Syntax mirrors .gitignore.
118
+
119
+ ```
120
+ # .forceignore
121
+
122
+ # Profiles -- use Permission Sets instead
123
+ **/profiles/**
124
+
125
+ # Standard Value Sets (cannot deploy, org-managed)
126
+ **/standardValueSets/**
127
+
128
+ # Managed Package components -- read-only
129
+ **/force-app/main/default/classes/fflib_*
130
+ **/force-app/main/default/classes/NPSP_*
131
+
132
+ # Experience Cloud templates (large, rarely need deploying)
133
+ **/experiences/**
134
+
135
+ # Reports and Dashboards (manage via UI)
136
+ **/reports/**
137
+ **/dashboards/**
138
+
139
+ # Translations (if not managing)
140
+ **/translations/**
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Retrieving Metadata
146
+
147
+ ### Retrieve by Metadata Type
148
+
149
+ ```bash
150
+ # Retrieve all Apex classes
151
+ sf project retrieve start \
152
+ --metadata ApexClass \
153
+ --target-org myOrg \
154
+ --output-dir force-app
155
+
156
+ # Retrieve specific component
157
+ sf project retrieve start \
158
+ --metadata "ApexClass:AccountService" \
159
+ --target-org myOrg
160
+
161
+ # Retrieve multiple types
162
+ sf project retrieve start \
163
+ --metadata "ApexClass,ApexTrigger,LightningComponentBundle,CustomObject" \
164
+ --target-org myOrg
165
+ ```
166
+
167
+ ### Retrieve via package.xml
168
+
169
+ ```bash
170
+ sf project retrieve start \
171
+ --manifest manifest/package.xml \
172
+ --target-org myOrg \
173
+ --output-dir force-app
174
+ ```
175
+
176
+ ### Retrieve with Source Tracking (scratch orgs)
177
+
178
+ ```bash
179
+ # Only retrieves what changed in org since last sync
180
+ sf project retrieve start \
181
+ --source-dir force-app \
182
+ --target-org myScratch
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Org Comparison Strategies
188
+
189
+ ### List Available Metadata
190
+
191
+ ```bash
192
+ sf org list metadata-types --target-org myOrg
193
+ sf org list metadata --metadata-type ApexClass --target-org myOrg
194
+ sf org list metadata --metadata-type Flow --target-org myOrg
195
+ ```
196
+
197
+ ### Compare Two Orgs
198
+
199
+ ```bash
200
+ # Retrieve from source and target orgs
201
+ sf project retrieve start --manifest manifest/package.xml --target-org sourceOrg --output-dir /tmp/source-org
202
+ sf project retrieve start --manifest manifest/package.xml --target-org targetOrg --output-dir /tmp/target-org
203
+
204
+ # Diff using standard tools
205
+ diff -r /tmp/source-org /tmp/target-org
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Managing Profiles vs Permission Sets
211
+
212
+ > Deploying a Profile from source replaces the entire profile definition in the target org. Any permissions that exist in the org but are not in your source file will be revoked. Use Permission Sets instead of Profiles for deployable permission management.
213
+
214
+ ```bash
215
+ # Add profile to .forceignore to stop tracking
216
+ echo "**/profiles/**" >> .forceignore
217
+
218
+ # Deploy permission sets instead
219
+ sf project deploy start \
220
+ --metadata "PermissionSet:Sales_Manager_Permissions" \
221
+ --target-org myOrg
222
+ ```
223
+
224
+ When profiles cannot be avoided:
225
+
226
+ ```bash
227
+ # Retrieve ONLY the profile
228
+ sf project retrieve start \
229
+ --metadata "Profile:Admin" \
230
+ --target-org myOrg
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Handling Org Conflicts
236
+
237
+ > `--ignore-conflicts` silently overwrites without prompting. Run `deploy preview` first to review what will be overwritten. Using `--ignore-conflicts` on a shared org can destroy another developer's uncommitted work.
238
+
239
+ ```bash
240
+ # Preview conflicts before deploying
241
+ sf project deploy preview --source-dir force-app --target-org myScratch
242
+
243
+ # Force deploy (local wins)
244
+ sf project deploy start \
245
+ --source-dir force-app \
246
+ --ignore-conflicts \
247
+ --target-org myScratch
248
+
249
+ # Force retrieve (org wins)
250
+ sf project retrieve start \
251
+ --source-dir force-app \
252
+ --ignore-conflicts \
253
+ --target-org myScratch
254
+ ```
255
+
256
+ ---
257
+
258
+ ## Custom Metadata Type Records
259
+
260
+ Custom Metadata Type records are metadata -- deploy them, not import them.
261
+
262
+ ```xml
263
+ <!-- force-app/main/default/customMetadata/Service_Config.Production.md-meta.xml -->
264
+ <?xml version="1.0" encoding="UTF-8"?>
265
+ <CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata">
266
+ <label>Production Config</label>
267
+ <protected>false</protected>
268
+ <values>
269
+ <field>Endpoint_URL__c</field>
270
+ <value xsi:type="xsd:string">https://api.example.com</value>
271
+ </values>
272
+ <values>
273
+ <field>Timeout_Ms__c</field>
274
+ <value xsi:type="xsd:double">10000</value>
275
+ </values>
276
+ </CustomMetadata>
277
+ ```
278
+
279
+ Benefits over Custom Settings: deployable, available in flows and formula fields, no governor limit on reads, can be packaged.
280
+
281
+ ---
282
+
283
+ ## Related
284
+
285
+ - **Constraints**: `sf-deployment-constraints` -- deployment safety rules
@@ -0,0 +1,372 @@
1
+ ---
2
+ name: sf-platform-events-cdc
3
+ description: >-
4
+ Salesforce Platform Events and CDC — Apex publish/subscribe, event replay, testing patterns. Use when designing event-driven integrations or data sync.
5
+ ---
6
+
7
+ # Platform Events & Change Data Capture
8
+
9
+ Procedures for building event-driven integrations using Platform Events and CDC. Allocation limits, retention windows, publish behavior details, and testing API specifics live in the reference file.
10
+
11
+ @../_reference/PLATFORM_EVENTS.md
12
+
13
+ ## When to Use
14
+
15
+ - Designing event-driven architecture within Salesforce or with external systems
16
+ - Implementing real-time data synchronization using Change Data Capture
17
+ - Building decoupled integrations with retry and replay capabilities
18
+ - Replacing polling-based integrations with push-based event notifications
19
+ - Implementing audit trails or data replication to external data stores
20
+
21
+ ---
22
+
23
+ ## Publishing Platform Events
24
+
25
+ ### From Apex
26
+
27
+ ```apex
28
+ public class OrderEventPublisher {
29
+ public static void publishOrderCompleted(List<Order> orders) {
30
+ List<Order_Completed__e> events = new List<Order_Completed__e>();
31
+
32
+ for (Order ord : orders) {
33
+ events.add(new Order_Completed__e(
34
+ Order_Id__c = ord.Id,
35
+ Total_Amount__c = ord.TotalAmount,
36
+ Customer_Id__c = ord.AccountId,
37
+ Fulfillment_Status__c = 'Pending'
38
+ ));
39
+ }
40
+
41
+ List<Database.SaveResult> results = EventBus.publish(events);
42
+
43
+ for (Integer i = 0; i < results.size(); i++) {
44
+ if (!results[i].isSuccess()) {
45
+ for (Database.Error err : results[i].getErrors()) {
46
+ System.debug(LoggingLevel.ERROR,
47
+ 'Event publish failed: ' + err.getStatusCode() +
48
+ ' - ' + err.getMessage());
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ ### Publish After Commit vs Publish Immediately
57
+
58
+ - **Publish After Commit** (default): Events are lost if the transaction rolls back. Use for business events.
59
+ - **Publish Immediately** (set in event definition in Setup): Events publish even if the transaction fails. Use for audit/error logging. Configured at the event level, not via code parameters.
60
+
61
+ ---
62
+
63
+ ## Subscribing to Platform Events
64
+
65
+ ### Apex Trigger Subscriber
66
+
67
+ ```apex
68
+ trigger OrderCompletedTrigger on Order_Completed__e (after insert) {
69
+ List<Task> followUpTasks = new List<Task>();
70
+
71
+ for (Order_Completed__e event : Trigger.new) {
72
+ followUpTasks.add(new Task(
73
+ Subject = 'Follow up on Order ' + event.Order_Id__c,
74
+ Description = 'Amount: ' + event.Total_Amount__c,
75
+ WhatId = Id.valueOf(event.Order_Id__c),
76
+ Status = 'Not Started',
77
+ Priority = event.Total_Amount__c > 100000 ? 'High' : 'Normal'
78
+ ));
79
+ }
80
+
81
+ if (!followUpTasks.isEmpty()) {
82
+ insert followUpTasks;
83
+ }
84
+ }
85
+ ```
86
+
87
+ **Trigger subscriber behavior:**
88
+
89
+ - Runs in its own transaction (separate from publisher)
90
+ - High-volume events: automatic retry up to 9 times over 24 hours
91
+ - Standard volume events: no automatic retries
92
+ - Batch size: up to 2,000 per batch for high-volume events
93
+
94
+ ### Retry and Checkpoint Pattern
95
+
96
+ ```apex
97
+ trigger OrderCompletedTrigger on Order_Completed__e (after insert) {
98
+ if (EventBus.TriggerContext.currentContext().retries > 9) {
99
+ List<Error_Log__c> errorLogs = new List<Error_Log__c>();
100
+ for (Order_Completed__e event : Trigger.new) {
101
+ errorLogs.add(new Error_Log__c(
102
+ Source__c = 'OrderCompletedTrigger',
103
+ Message__c = 'Max retries for order: ' + event.Order_Id__c
104
+ ));
105
+ }
106
+ insert errorLogs;
107
+ return;
108
+ }
109
+
110
+ try {
111
+ // Process events with checkpointing to avoid poison-pill blocking.
112
+ // processOrder() MUST be idempotent — on retry, it runs again for
113
+ // events between last checkpoint and failure point.
114
+ for (Order_Completed__e event : Trigger.new) {
115
+ processOrder(event);
116
+ EventBus.TriggerContext.currentContext()
117
+ .setResumeCheckpoint(event.ReplayId);
118
+ }
119
+ } catch (Exception e) {
120
+ throw new EventBus.RetryableException(
121
+ 'Transient failure: ' + e.getMessage());
122
+ }
123
+ }
124
+ ```
125
+
126
+ ### Flow Subscriber
127
+
128
+ ```
129
+ Flow Type: Platform Event-Triggered Flow
130
+ Object: Order_Completed__e
131
+ Trigger: When a platform event message is received
132
+
133
+ Elements:
134
+ 1. Get Records: Find matching Order by Order_Id__c
135
+ 2. Decision: Check if order needs fulfillment
136
+ 3. Update Records: Set Order.Status to 'Processing'
137
+ 4. Create Records: Create Shipment__c record
138
+ ```
139
+
140
+ ### External Subscribers
141
+
142
+ | Protocol | Use Case |
143
+ |----------|----------|
144
+ | CometD (Streaming API) | Legacy, browser-based (long polling) |
145
+ | Pub/Sub API (gRPC) | Modern, server-to-server (higher throughput) |
146
+
147
+ ---
148
+
149
+ ## Replay Mechanism
150
+
151
+ Every published event receives a **ReplayId** -- a monotonically increasing sequence number.
152
+
153
+ ```
154
+ Replay Options:
155
+ -1 -> Tip of stream (new events only)
156
+ -2 -> Earliest available (all retained events)
157
+ <specific-id> -> From that ReplayId forward
158
+ ```
159
+
160
+ ### Managing ReplayId in Apex
161
+
162
+ ```apex
163
+ public class EventReplayManager {
164
+ public static void updateReplayId(String eventType, String replayId) {
165
+ Event_Replay_Checkpoint__c checkpoint =
166
+ Event_Replay_Checkpoint__c.getInstance(eventType);
167
+ if (checkpoint == null) {
168
+ checkpoint = new Event_Replay_Checkpoint__c(
169
+ Name = eventType,
170
+ Last_Replay_Id__c = replayId
171
+ );
172
+ } else {
173
+ checkpoint.Last_Replay_Id__c = replayId;
174
+ }
175
+ upsert checkpoint;
176
+ }
177
+ }
178
+ ```
179
+
180
+ Concurrency note: Multiple subscribers may read the same checkpoint and reprocess overlapping events. Use ReplayId for deduplication.
181
+
182
+ ---
183
+
184
+ ## Change Data Capture (CDC)
185
+
186
+ CDC automatically publishes change events when records are created, updated, deleted, or undeleted.
187
+
188
+ ### Enabling CDC
189
+
190
+ Enable per object in Setup > Change Data Capture.
191
+
192
+ ```
193
+ Channel format:
194
+ Standard objects: /data/AccountChangeEvent
195
+ Custom objects: /data/MyObject__ChangeEvent
196
+ ```
197
+
198
+ ### Handling CDC in Apex
199
+
200
+ ```apex
201
+ trigger AccountChangeEventTrigger on AccountChangeEvent (after insert) {
202
+ for (AccountChangeEvent event : Trigger.new) {
203
+ EventBus.ChangeEventHeader header = event.ChangeEventHeader;
204
+
205
+ if (header.changedFields.contains('BillingCity')) {
206
+ System.debug('BillingCity changed to: ' + event.BillingCity);
207
+ }
208
+
209
+ switch on header.changeType {
210
+ when 'CREATE' { handleCreate(event); }
211
+ when 'UPDATE' { handleUpdate(event, header.changedFields); }
212
+ when 'DELETE' { handleDelete(header.recordIds); }
213
+ when 'UNDELETE' { handleUndelete(header.recordIds); }
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### Gap and Overflow Events
220
+
221
+ Gap events indicate missed events -- trigger a full sync.
222
+
223
+ ```apex
224
+ if (header.changeType == 'GAP_CREATE' || header.changeType == 'GAP_UPDATE'
225
+ || header.changeType == 'GAP_DELETE' || header.changeType == 'GAP_UNDELETE'
226
+ || header.changeType == 'GAP_OVERFLOW') {
227
+ initiateFullSync(header.entityName);
228
+ }
229
+ ```
230
+
231
+ Overflow events occur when a single transaction modifies >100,000 records.
232
+
233
+ ---
234
+
235
+ ## Event-Driven Architecture Patterns
236
+
237
+ ### Decoupled Integration
238
+
239
+ ```
240
+ Salesforce (Publisher) ---> Platform Event ---> External System (Subscriber)
241
+ ```
242
+
243
+ Publisher does not know or care who subscribes. New subscribers added without modifying publisher code.
244
+
245
+ ### Saga Pattern (Multi-Step Transaction)
246
+
247
+ ```
248
+ Order Created -> PE: Order_Created__e
249
+ Inventory Reserved -> PE: Inventory_Reserved__e
250
+ Payment Processed -> PE: Payment_Processed__e
251
+ Order Fulfilled -> PE: Order_Fulfilled__e
252
+ If any step fails -> PE: Order_Compensation__e (rollback)
253
+ ```
254
+
255
+ Each step is an independent transaction. Compensation events handle rollback.
256
+
257
+ ### CDC for Real-Time Sync
258
+
259
+ ```
260
+ Salesforce -> CDC Events -> Data Lake / Warehouse
261
+ (AccountChangeEvent, ContactChangeEvent, etc.)
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Testing Platform Events
267
+
268
+ ### Testing Event Publishing
269
+
270
+ ```apex
271
+ @isTest
272
+ static void testOrderEventPublishing() {
273
+ Order testOrder = new Order(
274
+ AccountId = testAccountId,
275
+ TotalAmount = 50000,
276
+ Status = 'Draft'
277
+ );
278
+ insert testOrder;
279
+
280
+ Test.startTest();
281
+ OrderEventPublisher.publishOrderCompleted(new List<Order>{ testOrder });
282
+ Test.stopTest();
283
+
284
+ // Verify via SaveResult
285
+ List<Order_Completed__e> events = new List<Order_Completed__e>();
286
+ events.add(new Order_Completed__e(
287
+ Order_Id__c = testOrder.Id,
288
+ Total_Amount__c = testOrder.TotalAmount
289
+ ));
290
+ List<Database.SaveResult> results = EventBus.publish(events);
291
+ Test.getEventBus().deliver();
292
+
293
+ Assert.isTrue(results[0].isSuccess());
294
+ }
295
+ ```
296
+
297
+ ### Testing Event Subscribers
298
+
299
+ ```apex
300
+ @isTest
301
+ static void testOrderCompletedSubscriber() {
302
+ Account testAccount = new Account(Name = 'Test Account');
303
+ insert testAccount;
304
+
305
+ Order_Completed__e event = new Order_Completed__e(
306
+ Order_Id__c = 'ORD-001',
307
+ Total_Amount__c = 75000,
308
+ Customer_Id__c = testAccount.Id,
309
+ Fulfillment_Status__c = 'Pending'
310
+ );
311
+
312
+ Test.startTest();
313
+ EventBus.publish(event);
314
+ Test.getEventBus().deliver();
315
+ Test.stopTest();
316
+
317
+ List<Task> tasks = [SELECT Id, Priority FROM Task
318
+ WHERE Subject LIKE '%ORD-001%'];
319
+ System.assertEquals(1, tasks.size());
320
+ System.assertEquals('Normal', tasks[0].Priority);
321
+ }
322
+ ```
323
+
324
+ ### Testing CDC Triggers
325
+
326
+ ```apex
327
+ @isTest
328
+ static void testAccountChangeEventTrigger() {
329
+ Account acc = new Account(Name = 'Original Name');
330
+ insert acc;
331
+
332
+ Test.startTest();
333
+ acc.Name = 'Updated Name';
334
+ acc.BillingCity = 'San Francisco';
335
+ update acc;
336
+ Test.getEventBus().deliver();
337
+ Test.stopTest();
338
+
339
+ // Assert on whatever side-effects your trigger produces
340
+ }
341
+ ```
342
+
343
+ ---
344
+
345
+ ## Monitoring and Troubleshooting
346
+
347
+ ### EventBusSubscriber Query
348
+
349
+ ```apex
350
+ List<EventBusSubscriber> subscribers = [
351
+ SELECT Name, Position, Retries, LastError, Status, Topic
352
+ FROM EventBusSubscriber
353
+ WHERE Topic = '/event/Order_Completed__e'
354
+ ];
355
+ ```
356
+
357
+ ### Common Issues
358
+
359
+ | Symptom | Cause | Fix |
360
+ |---------|-------|-----|
361
+ | Events not received | Subscriber suspended after max retries | Check EventBusSubscriber.Status, resume |
362
+ | Events out of order | Parallel processing | Use sequenceNumber to reorder |
363
+ | Missing events | Retention period exceeded | Implement checkpoint, reduce lag |
364
+ | Gap events received | System overload | Implement full-sync fallback |
365
+ | LIMIT_EXCEEDED on publish | Exceeded daily allocation | Batch publishes, check edition limits |
366
+
367
+ ---
368
+
369
+ ## Related
370
+
371
+ - Constraints: sf-apex-constraints
372
+ - Reference: @../_reference/PLATFORM_EVENTS.md, @../_reference/INTEGRATION_PATTERNS.md