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,274 @@
1
+ ---
2
+ name: sf-data-modeling
3
+ description: >-
4
+ Use when designing Salesforce custom objects, relationships, Custom Metadata, or sharing models for scalable org architecture. Do NOT use for SOQL optimization or Apex patterns.
5
+ ---
6
+
7
+ # Salesforce Data Modeling
8
+
9
+ @../_reference/DATA_MODELING.md
10
+
11
+ ## When to Use
12
+
13
+ - Designing new custom objects, fields, or relationships
14
+ - Deciding between lookup vs master-detail relationships
15
+ - Planning record types, page layouts, or sharing model architecture
16
+ - Architecting for large data volumes (LDV) requiring index-aware field design
17
+ - Reviewing or refactoring an existing data model
18
+ - Evaluating external objects, custom metadata types, or hierarchical settings
19
+
20
+ ## Object Design Principles
21
+
22
+ ### Extend Standard Objects When Possible
23
+
24
+ | Business Need | Use Standard Object | Not Custom |
25
+ |---|---|---|
26
+ | Customer companies | Account | Company__c |
27
+ | Individual contacts | Contact | Person__c |
28
+ | Sales deals | Opportunity | Deal__c |
29
+ | Support tickets | Case | Ticket__c |
30
+ | Events/meetings | Event | Meeting__c |
31
+ | Tasks/to-dos | Task | Todo__c |
32
+ | Products/pricing | Product2, PricebookEntry | Product__c |
33
+ | Orders | Order, OrderItem | PurchaseOrder__c |
34
+
35
+ Standard objects come with built-in reports, process automations, and integrations.
36
+
37
+ ### Custom Object Naming
38
+
39
+ ```
40
+ API Name: ProjectTask__c (PascalCase + __c)
41
+ Label: Project Task (human-readable)
42
+ Plural: Project Tasks
43
+ Relationship Name: ProjectTasks (plural for child relationship)
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Relationship Types
49
+
50
+ | Relationship | Cascade Delete | Roll-Up Summary | Required | Sharing Inherited |
51
+ |---|---|---|---|---|
52
+ | Lookup | No (configurable) | No | No | No |
53
+ | Master-Detail | Yes | Yes | Yes | Yes |
54
+ | Many-to-Many (Junction) | Both sides | From junction | Both | From primary master |
55
+ | Hierarchical | No | No | No | No |
56
+ | External Lookup | No | No | No | No |
57
+
58
+ *Master-Detail can be reparented if "Allow Reparenting" is enabled.
59
+
60
+ ### When to Use Lookup
61
+
62
+ - Child can exist independently (Contact without Account)
63
+ - No roll-up summaries needed
64
+ - Child needs its own sharing settings
65
+ - Multiple lookups, none is primary
66
+
67
+ ### When to Use Master-Detail
68
+
69
+ - Child has no meaning without parent (Order Line Item without Order)
70
+ - Roll-up summary fields needed on parent
71
+ - Child deleted when parent deleted
72
+ - Child sharing inherits from parent
73
+
74
+ ```xml
75
+ <!-- Master-Detail field metadata -->
76
+ <fields>
77
+ <fullName>Project__c</fullName>
78
+ <label>Project</label>
79
+ <type>MasterDetail</type>
80
+ <referenceTo>Project__c</referenceTo>
81
+ <relationshipLabel>Project Tasks</relationshipLabel>
82
+ <relationshipName>ProjectTasks</relationshipName>
83
+ <relationshipOrder>0</relationshipOrder>
84
+ <reparentableMasterDetail>false</reparentableMasterDetail>
85
+ </fields>
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Field Type Guide
91
+
92
+ | Field Type | Use When | Avoid When |
93
+ |---|---|---|
94
+ | Text (255) | Short single-line text | Long descriptions |
95
+ | Long Text Area | Up to 131,072 chars | Need to filter/search on it |
96
+ | Rich Text Area | HTML-formatted content | Need to query/filter by content |
97
+ | Number | Integers, no currency | Financial values (use Currency) |
98
+ | Currency | Monetary values | Non-financial numbers |
99
+ | Date | Date without time | Need time zone info |
100
+ | DateTime | Timestamps, audit trails | Simple date records |
101
+ | Checkbox | Boolean yes/no | Optional boolean (use Picklist) |
102
+ | Picklist (single) | Controlled vocabulary | Many values (use Lookup) |
103
+ | Picklist (multi) | Multiple selections | Filtering/reporting (anti-pattern) |
104
+ | Formula | Calculated, read-only | Values needing DML update |
105
+ | Roll-Up Summary | Aggregate child data | 25 per object (default limit) |
106
+ | External ID | Upsert key from external system | - |
107
+
108
+ ### Multi-Select Picklist Warning
109
+
110
+ ```apex
111
+ // Limited SOQL support — can use INCLUDES/EXCLUDES but not = or IN
112
+ List<Case> cases = [
113
+ SELECT Id FROM Case
114
+ WHERE Tag_List__c INCLUDES ('Billing', 'Technical')
115
+ ];
116
+ // Cannot use in GROUP BY, ORDER BY, or most aggregates
117
+ // Consider Lookup to a Tags junction object for complex tagging
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Custom Metadata Types vs Custom Settings vs Custom Labels
123
+
124
+ | Feature | Custom Metadata | Custom Settings | Custom Labels |
125
+ |---|---|---|---|
126
+ | Deployable | Yes | No (hierarchy)/Yes (list) | Yes |
127
+ | Per-user/profile values | No | Yes (hierarchy) | No |
128
+ | Governor limit on reads | No (cached) | Yes (SOQL equivalent) | No |
129
+ | Best for | Config deployed with code | User/profile-specific settings | Translatable strings |
130
+
131
+ ```apex
132
+ // Custom Metadata — no SOQL limits, deployable
133
+ String endpoint = Service_Config__mdt.getInstance('Production').Endpoint_URL__c;
134
+
135
+ // Custom Setting — profile-specific
136
+ Boolean isEnabled = Integration_Settings__c.getInstance().Is_Enabled__c;
137
+
138
+ // Custom Label — translatable
139
+ String welcomeMsg = System.Label.Welcome_Message;
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Record Types
145
+
146
+ ### When to Use
147
+
148
+ - Different page layouts per user group
149
+ - Different picklist values per business process
150
+ - Different automation processes per record type
151
+
152
+ ### When NOT to Use
153
+
154
+ - Simple field-level differences (use conditional visibility)
155
+ - Access control (use sharing rules or permission sets)
156
+ - Fundamentally different data structures (use separate objects)
157
+
158
+ ```apex
159
+ Id caseRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName()
160
+ .get('Internal_Support').getRecordTypeId();
161
+
162
+ List<Case> internalCases = [
163
+ SELECT Id, Subject FROM Case
164
+ WHERE RecordTypeId = :caseRecordTypeId WITH USER_MODE
165
+ ];
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Sharing Model Design
171
+
172
+ ### Object-Wide Defaults (OWD)
173
+
174
+ | OWD Setting | Other Users | Best For |
175
+ |---|---|---|
176
+ | Public Read/Write | Read + Write | Reference/config data |
177
+ | Public Read Only | Read only | Products, pricebooks |
178
+ | Private | None | Accounts, Opportunities |
179
+ | Controlled by Parent | Inherits | Master-Detail children |
180
+
181
+ Start with Private OWD for sensitive objects and open up with sharing rules.
182
+
183
+ ### Apex Managed Sharing
184
+
185
+ ```apex
186
+ public with sharing class ProjectSharingService {
187
+ public static void shareProjectWithUser(Id projectId, Id userId, String accessLevel) {
188
+ Project__Share shareRecord = new Project__Share(
189
+ ParentId = projectId,
190
+ UserOrGroupId = userId,
191
+ AccessLevel = accessLevel,
192
+ RowCause = Schema.Project__Share.RowCause.Manual
193
+ );
194
+ Database.SaveResult result = Database.insert(shareRecord, false);
195
+ if (!result.isSuccess() &&
196
+ result.getErrors()[0].getStatusCode() != StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION) {
197
+ throw new SharingException('Failed to share: ' + result.getErrors()[0].getMessage());
198
+ }
199
+ }
200
+ public class SharingException extends Exception {}
201
+ }
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Large Data Volume (LDV) Considerations
207
+
208
+ Objects with >100,000 records require special attention.
209
+
210
+ **Schema design:**
211
+
212
+ - Add external ID fields on objects queried by non-Id values
213
+ - Request custom indexes on fields used in WHERE clauses
214
+ - Consider skinny tables for frequently-accessed field subsets
215
+ - Avoid Roll-Up Summary fields on LDV child objects (use batch triggers instead)
216
+
217
+ ```apex
218
+ // Good — uses indexed fields, selective
219
+ List<Order__c> orders = [
220
+ SELECT Id, Status__c FROM Order__c
221
+ WHERE AccountId = :accountId
222
+ AND CreatedDate >= :thirtyDaysAgo
223
+ LIMIT 200
224
+ ];
225
+ ```
226
+
227
+ **Archiving:** Move old records to BigObjects or external archive. Use batch jobs for archive-and-delete.
228
+
229
+ ---
230
+
231
+ ## Junction Object Patterns
232
+
233
+ ```
234
+ Account <-- AccountContactRelation --> Contact
235
+ + Role (picklist)
236
+ + IsPrimary (checkbox)
237
+ + StartDate (date)
238
+ ```
239
+
240
+ - Junction objects with Master-Detail on both sides inherit sharing from BOTH parents
241
+ - Add meaningful fields to the junction (Role, Start Date, Status)
242
+ - Use `AccountContactRelation` (standard) before creating custom junctions for Account-Contact
243
+
244
+ ---
245
+
246
+ ## External Object Patterns
247
+
248
+ | Adapter | Use When |
249
+ |---|---|
250
+ | OData 2.0/4.0 | External REST API with OData support |
251
+ | Custom Adapter | Proprietary API or database |
252
+ | Cross-Org | Another Salesforce org |
253
+
254
+ External Objects have no triggers, Flows, or Validation Rules. Use Apex callouts for write operations.
255
+
256
+ ---
257
+
258
+ ## Anti-Patterns
259
+
260
+ | Anti-Pattern | Fix |
261
+ |---|---|
262
+ | Polymorphic lookup abuse | Use explicit lookup fields per related object |
263
+ | Over-normalization | Flatten into fields unless multiple addresses per record |
264
+ | Too many custom fields (800 limit) | Split into related child objects |
265
+ | Circular Master-Detail | Break the circle with a Lookup on one side |
266
+ | Text instead of Lookup | Use Lookup fields for referential integrity |
267
+ | Ignoring LDV on 100K+ objects | Request custom indexes, use skinny tables |
268
+
269
+ ---
270
+
271
+ ## Related
272
+
273
+ - **Agent**: `sf-architect` — For interactive, in-depth guidance
274
+ - **Constraints**: `sf-apex-constraints` — Governor limits and Apex safety rules
@@ -0,0 +1,362 @@
1
+ ---
2
+ name: sf-debugging
3
+ description: >-
4
+ Salesforce debugging — debug logs, SOQL explain plan, Flow debug, LWC DevTools, error resolution. Use when diagnosing Apex exceptions, governor breaches, or Flow failures. Do NOT use for tests or build errors.
5
+ ---
6
+
7
+ # Salesforce Debugging Techniques
8
+
9
+ Reference: @../_reference/DEBUGGING_TOOLS.md
10
+
11
+ ## When to Use
12
+
13
+ - When an Apex exception occurs and you need to trace it through logs
14
+ - When a governor limit is being exceeded and you need the root cause
15
+ - When a Flow or Process Builder is failing silently or producing unexpected results
16
+ - When an LWC component is not rendering data or throwing JavaScript errors
17
+ - When a callout is failing and you need to inspect request/response payloads
18
+ - When onboarding to a new org and diagnosing pre-existing error patterns
19
+
20
+ ---
21
+
22
+ ## Debug Log Setup
23
+
24
+ ### Enabling Debug Logging
25
+
26
+ **Via SF CLI (stream live logs):**
27
+
28
+ ```bash
29
+ # Stream all logs for the org in real time
30
+ sf apex tail log --target-org myOrg
31
+
32
+ # Stream logs with specific debug level
33
+ sf apex tail log \
34
+ --target-org myOrg \
35
+ --debug-level SFDC_DevConsole
36
+
37
+ # Retrieve a specific log by ID
38
+ sf apex get log \
39
+ --log-id 07L5e000000XXXXX \
40
+ --target-org myOrg
41
+
42
+ # List recent logs
43
+ sf apex list log --target-org myOrg
44
+
45
+ # Run anonymous Apex and capture log
46
+ sf apex run \
47
+ --file scripts/apex/debug-script.apex \
48
+ --target-org myOrg
49
+
50
+ # Run and save full log
51
+ sf apex run \
52
+ --file scripts/apex/debug-script.apex \
53
+ --target-org myOrg > debug-output.txt
54
+ ```
55
+
56
+ **Via Setup UI:**
57
+
58
+ 1. Setup > Debug Logs (under Environments)
59
+ 2. Click "New" under Monitored Users
60
+ 3. Select user, set expiration and log level
61
+ 4. Reproduce the issue
62
+ 5. Click the log entry to open it
63
+
64
+ **Via Developer Console:**
65
+
66
+ 1. Open: `sf org open --target-org myOrg`
67
+ 2. Click "Developer Console" (gear icon or App Launcher)
68
+ 3. Debug > Change Log Levels
69
+ 4. Set user-specific debug levels
70
+
71
+ ---
72
+
73
+ ## Reading Debug Logs
74
+
75
+ Debug logs have a maximum size of 20 MB. Logs exceeding this are truncated from the middle. If you see gaps, reduce log level verbosity or narrow the operation scope.
76
+
77
+ ### Key Sections in a Log
78
+
79
+ ```
80
+ 15:23:01.001 (1234567)|EXECUTION_STARTED
81
+ 15:23:01.012 (12345678)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
82
+ 15:23:01.015 (15000000)|SOQL_EXECUTE_BEGIN|[12]|Aggregations:0|SELECT Id FROM Account
83
+ 15:23:01.045 (45000000)|SOQL_EXECUTE_END|[12]|Rows:150
84
+ 15:23:01.050 (50000000)|USER_DEBUG|[15]|DEBUG|Processing 150 accounts
85
+ 15:23:01.200 (200000000)|DML_BEGIN|[22]|Op:Insert|Type:Contact|Rows:150
86
+ 15:23:01.350 (350000000)|DML_END|[22]
87
+ 15:23:01.400 (400000000)|CUMULATIVE_LIMIT_USAGE
88
+ Number of SOQL queries: 3 out of 100
89
+ Number of DML rows: 150 out of 10000
90
+ Maximum CPU time: 452 out of 10000
91
+ 15:23:01.401 (401000000)|EXECUTION_FINISHED
92
+ ```
93
+
94
+ ### Finding CPU Hogs
95
+
96
+ Compare timestamps between BEGIN/END pairs to identify slow operations:
97
+
98
+ ```bash
99
+ # Find slow operations by comparing BEGIN/END timestamps
100
+ grep -E "SOQL_EXECUTE_BEGIN|SOQL_EXECUTE_END|DML_BEGIN|DML_END" debug.log
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Developer Console
106
+
107
+ ### Anonymous Apex Execution
108
+
109
+ ```apex
110
+ // Open Developer Console > Execute Anonymous (Ctrl+E / Cmd+E)
111
+ Account acc = [SELECT Id FROM Account WHERE Name = 'Test Corp' LIMIT 1];
112
+ AccountService svc = new AccountService();
113
+ AccountService.AccountResult result = svc.getAccount(acc.Id);
114
+ System.debug(LoggingLevel.ERROR, JSON.serializePretty(result));
115
+ ```
116
+
117
+ ### Query Editor
118
+
119
+ ```sql
120
+ -- Developer Console > Query Editor tab
121
+ SELECT Id, Name, StageName, Amount, CloseDate
122
+ FROM Opportunity
123
+ WHERE StageName = 'Negotiation'
124
+ AND CloseDate = THIS_QUARTER
125
+ ORDER BY Amount DESC
126
+ LIMIT 25
127
+ ```
128
+
129
+ Use "Query Plan" button to analyse query performance (see SOQL Query Plan section below).
130
+
131
+ ### Checkpoints (Heap Inspection)
132
+
133
+ 1. Debug > Add/Remove Checkpoint (on a code line)
134
+ 2. Execute code that runs through the checkpointed line
135
+ 3. Debug > Checkpoint Inspector -- see heap contents, variable values
136
+
137
+ ---
138
+
139
+ ## SOQL Query Plan (Explain Plan)
140
+
141
+ ### How to Access
142
+
143
+ 1. Developer Console > Query Editor
144
+ 2. Write your query
145
+ 3. Click "Query Plan" button (not "Execute")
146
+
147
+ ### Optimising Based on Plan
148
+
149
+ ```soql
150
+ -- BAD: Cost = 2.5 (TableScan)
151
+ SELECT Id FROM Account WHERE Description LIKE '%enterprise%'
152
+
153
+ -- GOOD: Cost = 0.1 (Index on ExternalId__c)
154
+ SELECT Id FROM Account WHERE ExternalId__c = 'ACC-001'
155
+
156
+ -- GOOD: Cost = 0.3 (Index on OwnerId)
157
+ SELECT Id FROM Account WHERE OwnerId = :currentUserId
158
+ ```
159
+
160
+ ---
161
+
162
+ ## VS Code Apex Debugger
163
+
164
+ ### Apex Replay Debugger (Free)
165
+
166
+ Available in all editions with the Salesforce Extension Pack:
167
+
168
+ 1. Capture a debug log (via SF CLI, Developer Console, or Setup)
169
+ 2. Open the `.log` file in VS Code
170
+ 3. Command Palette: "SFDX: Launch Apex Replay Debugger with Current File"
171
+ 4. Set breakpoints in `.cls` files
172
+ 5. Step through execution, inspect variables and the call stack
173
+
174
+ ### Interactive Apex Debugger (Paid)
175
+
176
+ Requires Performance Edition, Unlimited Edition, or Enterprise Edition add-on. Not available in Developer Edition.
177
+
178
+ #### Launch Configuration
179
+
180
+ ```json
181
+ // .vscode/launch.json
182
+ {
183
+ "version": "0.2.0",
184
+ "configurations": [
185
+ {
186
+ "name": "Launch Apex Debugger",
187
+ "type": "apex",
188
+ "request": "launch",
189
+ "userIdFilter": [],
190
+ "requestTypeFilter": [],
191
+ "entryPointFilter": "",
192
+ "salesforceProject": "${workspaceRoot}"
193
+ }
194
+ ]
195
+ }
196
+ ```
197
+
198
+ #### Debugging Steps
199
+
200
+ 1. Set breakpoints in `.cls` files (click gutter)
201
+ 2. Run > Start Debugging (F5) with "Launch Apex Debugger"
202
+ 3. Reproduce the action in Salesforce UI
203
+ 4. VS Code pauses at breakpoint
204
+ 5. Inspect variables, Step Over (F10), Step Into (F11), Continue (F5)
205
+
206
+ ---
207
+
208
+ ## Common Errors: Root Causes and Fixes
209
+
210
+ ### System.LimitException: Too many SOQL queries: 101
211
+
212
+ **Root cause:** SOQL query inside a loop
213
+
214
+ ```apex
215
+ // WRONG -- SOQL in loop
216
+ for (Account acc : Trigger.new) {
217
+ List<Contact> contacts = [SELECT Id FROM Contact WHERE AccountId = :acc.Id];
218
+ }
219
+
220
+ // FIX -- single query outside loop
221
+ Map<Id, List<Contact>> contactsByAccount = new Map<Id, List<Contact>>();
222
+ for (Contact c : [SELECT Id, AccountId FROM Contact WHERE AccountId IN :Trigger.newMap.keySet()]) {
223
+ if (!contactsByAccount.containsKey(c.AccountId)) {
224
+ contactsByAccount.put(c.AccountId, new List<Contact>());
225
+ }
226
+ contactsByAccount.get(c.AccountId).add(c);
227
+ }
228
+ ```
229
+
230
+ ### Apex CPU time limit exceeded
231
+
232
+ **Root cause:** Complex nested loops, excessive string operations
233
+
234
+ ```apex
235
+ // WRONG -- O(n^2) loop
236
+ for (Account acc : accounts) {
237
+ for (Contact con : allContacts) {
238
+ if (con.AccountId == acc.Id) { /* ... */ }
239
+ }
240
+ }
241
+
242
+ // FIX -- use Map for O(1) lookup
243
+ Map<Id, List<Contact>> contactsByAccount = buildContactMap(allContacts);
244
+ for (Account acc : accounts) {
245
+ List<Contact> accountContacts = contactsByAccount.get(acc.Id);
246
+ }
247
+ ```
248
+
249
+ ### System.NullPointerException
250
+
251
+ **Root cause:** Unchecked null reference
252
+
253
+ ```apex
254
+ // PREFERRED (API 56.0+) -- null-safe navigation
255
+ String upperName = account.Name?.toUpperCase() ?? '';
256
+ String accountName = contact?.Account?.Name ?? 'No Account';
257
+ ```
258
+
259
+ ### UNABLE_TO_LOCK_ROW
260
+
261
+ **Root cause:** Two concurrent transactions updating the same record(s). Fix with retry logic (Queueable), `FOR UPDATE` in SOQL, or reducing batch size.
262
+
263
+ ### MIXED_DML_OPERATION
264
+
265
+ **Root cause:** Setup objects (User, Profile) and non-setup objects in the same transaction. Separate with `@future` or `System.runAs()` in tests.
266
+
267
+ ### Too many DML rows: 10001
268
+
269
+ **Root cause:** DML on >10,000 records. Use Batch Apex to process in chunks.
270
+
271
+ ### Callout from triggers are not supported
272
+
273
+ **Root cause:** Synchronous callout in trigger context. Use `@future(callout=true)`.
274
+
275
+ ---
276
+
277
+ ## Flow Debugging
278
+
279
+ ### Flow Debug Mode
280
+
281
+ 1. Setup > Flows > Open Flow Builder
282
+ 2. Click "Debug" button (top right)
283
+ 3. Set input variables and "Run as" user
284
+ 4. Click "Run"
285
+ 5. Step through elements, inspect variable values
286
+ 6. "Rollback" checkbox: undo DML changes during debug
287
+
288
+ ### Common Flow Errors
289
+
290
+ | Error | Root Cause | Fix |
291
+ |-------|-----------|-----|
292
+ | "An unhandled fault has occurred" | Missing fault connectors | Add fault paths on all DML/callout elements |
293
+ | Flow SOQL 101 limit exceeded | Get Records inside a loop | Move Get Records outside loop, use Collection Filtering |
294
+ | "This flow can't access the variable" | Variable not marked for input/output | Enable "Available for input/output" on the variable |
295
+
296
+ ---
297
+
298
+ ## LWC Debugging
299
+
300
+ ### Browser Developer Tools
301
+
302
+ ```javascript
303
+ import { LightningElement, wire } from 'lwc';
304
+
305
+ export default class AccountCard extends LightningElement {
306
+ connectedCallback() {
307
+ console.group('AccountCard mounted');
308
+ console.log('accountId:', this.accountId);
309
+ console.groupEnd();
310
+ }
311
+
312
+ handleError(error) {
313
+ console.error('AccountCard error:', JSON.stringify(error));
314
+ }
315
+ }
316
+ ```
317
+
318
+ ### Enable Lightning Debug Mode
319
+
320
+ 1. Setup > Session Settings
321
+ 2. Enable "Enable Debug Mode for Lightning Components"
322
+ 3. Slower but provides better error messages and unminified source
323
+
324
+ ### Chrome Extensions
325
+
326
+ Install "Salesforce Inspector Reloaded" for real-time metadata browsing, direct record access, API Inspector, and SOQL query runner.
327
+
328
+ ---
329
+
330
+ ## Integration Debugging
331
+
332
+ ### Capture Callout Logs
333
+
334
+ ```apex
335
+ public class DebugCalloutService {
336
+ public static HttpResponse send(HttpRequest req) {
337
+ System.debug(LoggingLevel.INFO, 'CALLOUT REQUEST: ' + req.getMethod() + ' ' + req.getEndpoint());
338
+ System.debug(LoggingLevel.FINE, 'REQUEST BODY: ' + req.getBody());
339
+ Http http = new Http();
340
+ HttpResponse res = http.send(req);
341
+ System.debug(LoggingLevel.INFO, 'CALLOUT RESPONSE: ' + res.getStatusCode());
342
+ System.debug(LoggingLevel.FINE, 'RESPONSE BODY: ' + res.getBody());
343
+ return res;
344
+ }
345
+ }
346
+ ```
347
+
348
+ ### Viewing Callout Details in Debug Log
349
+
350
+ With `CALLOUT: FINE` level enabled:
351
+
352
+ ```
353
+ CALLOUT_REQUEST|....|POST https://api.example.com/orders
354
+ CALLOUT_RESPONSE|....|200 {"orderId":"123","status":"OK"}
355
+ ```
356
+
357
+ ---
358
+
359
+ ## Related
360
+
361
+ - **Agent**: `sf-review-agent` -- for interactive, in-depth guidance
362
+ - **Constraints**: `sf-apex-constraints` -- governor limits and Apex coding rules