@salesforce/afv-skills 1.5.0 → 1.5.2

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 (68) hide show
  1. package/README.md +16 -415
  2. package/package.json +5 -3
  3. package/skills/building-ui-bundle-app/SKILL.md +325 -0
  4. package/skills/building-ui-bundle-frontend/SKILL.md +122 -0
  5. package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/component.md +1 -1
  6. package/skills/creating-b2b-commerce-store/SKILL.md +169 -0
  7. package/skills/creating-b2b-commerce-store/references/store-vs-storefront.md +169 -0
  8. package/skills/deploying-ui-bundle/SKILL.md +77 -0
  9. package/skills/generating-apex/CREDITS.md +30 -0
  10. package/skills/generating-apex/SKILL.md +399 -0
  11. package/skills/generating-apex/assets/abstract.cls +132 -0
  12. package/skills/generating-apex/assets/batch.cls +125 -0
  13. package/skills/generating-apex/assets/domain.cls +102 -0
  14. package/skills/generating-apex/assets/dto.cls +108 -0
  15. package/skills/generating-apex/assets/exception.cls +51 -0
  16. package/skills/generating-apex/assets/interface.cls +25 -0
  17. package/skills/generating-apex/assets/invocable.cls +115 -0
  18. package/skills/generating-apex/assets/queueable.cls +92 -0
  19. package/skills/generating-apex/assets/rest-resource.cls +300 -0
  20. package/skills/generating-apex/assets/schedulable.cls +75 -0
  21. package/skills/generating-apex/assets/selector.cls +92 -0
  22. package/skills/generating-apex/assets/service.cls +69 -0
  23. package/skills/generating-apex/assets/trigger.cls +45 -0
  24. package/skills/generating-apex/assets/utility.cls +97 -0
  25. package/skills/generating-apex/references/AccountDeduplicationBatch.cls +148 -0
  26. package/skills/generating-apex/references/AccountSelector.cls +193 -0
  27. package/skills/generating-apex/references/AccountService.cls +201 -0
  28. package/skills/generating-apex-test/CREDITS.md +30 -0
  29. package/skills/generating-apex-test/SKILL.md +199 -0
  30. package/skills/generating-apex-test/assets/test-class-template.cls +93 -0
  31. package/skills/generating-apex-test/assets/test-data-factory-template.cls +111 -0
  32. package/skills/generating-apex-test/references/assertion-patterns.md +108 -0
  33. package/skills/generating-apex-test/references/async-testing.md +193 -0
  34. package/skills/generating-apex-test/references/mocking-patterns.md +220 -0
  35. package/skills/generating-apex-test/references/test-data-factory.md +75 -0
  36. package/skills/generating-experience-react-site/SKILL.md +20 -9
  37. package/skills/generating-experience-react-site/docs/configure-metadata-digital-experience.md +1 -1
  38. package/skills/generating-flexipage/SKILL.md +58 -60
  39. package/skills/generating-ui-bundle-features/SKILL.md +45 -0
  40. package/skills/generating-ui-bundle-metadata/SKILL.md +106 -0
  41. package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/SKILL.md +5 -5
  42. package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/constraints.md +2 -2
  43. package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/examples.md +1 -1
  44. package/skills/{implementing-webapp-file-upload → implementing-ui-bundle-file-upload}/SKILL.md +11 -11
  45. package/skills/searching-media/SKILL.md +342 -0
  46. package/skills/{using-webapp-salesforce-data → using-ui-bundle-salesforce-data}/SKILL.md +52 -25
  47. package/skills/using-ui-bundle-salesforce-data/references/mutation-query-generation.md +140 -0
  48. package/skills/using-ui-bundle-salesforce-data/references/query-testing.md +78 -0
  49. package/skills/using-ui-bundle-salesforce-data/references/read-query-generation.md +307 -0
  50. package/skills/using-ui-bundle-salesforce-data/references/schema-introspection.md +53 -0
  51. package/skills/using-ui-bundle-salesforce-data/references/ui-bundle-integration.md +221 -0
  52. package/skills/{using-webapp-salesforce-data → using-ui-bundle-salesforce-data/scripts}/graphql-search.sh +75 -23
  53. package/skills/building-webapp-data-visualization/SKILL.md +0 -72
  54. package/skills/building-webapp-data-visualization/implementation/bar-line-chart.md +0 -316
  55. package/skills/building-webapp-data-visualization/implementation/dashboard-layout.md +0 -189
  56. package/skills/building-webapp-data-visualization/implementation/donut-chart.md +0 -181
  57. package/skills/building-webapp-data-visualization/implementation/stat-card.md +0 -150
  58. package/skills/building-webapp-react-components/SKILL.md +0 -96
  59. package/skills/configuring-webapp-csp-trusted-sites/SKILL.md +0 -90
  60. package/skills/configuring-webapp-metadata/SKILL.md +0 -158
  61. package/skills/creating-webapp/SKILL.md +0 -140
  62. package/skills/deploying-webapp-to-salesforce/SKILL.md +0 -226
  63. package/skills/installing-webapp-features/SKILL.md +0 -210
  64. /package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/header-footer.md +0 -0
  65. /package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/page.md +0 -0
  66. /package/skills/{configuring-webapp-csp-trusted-sites/implementation/metadata-format.md → generating-ui-bundle-metadata/implementation/csp-metadata-format.md} +0 -0
  67. /package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/style-tokens.md +0 -0
  68. /package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/troubleshooting.md +0 -0
@@ -0,0 +1,169 @@
1
+ # Commerce Store vs Storefront: Technical Reference
2
+
3
+ ## Overview
4
+
5
+ Understanding the distinction between Commerce Store and Storefront is critical for successful Commerce B2B development. This document provides technical details about these two components and explains why they must be created in a specific order.
6
+
7
+ ---
8
+
9
+ ## The Two Components
10
+
11
+ ### 1. Commerce Store (Backend Data)
12
+
13
+ **What it is:**
14
+ - Runtime data and configuration created in the Salesforce org
15
+ - NOT source-controllable metadata
16
+ - Created through Commerce app UI
17
+
18
+ **What it includes:**
19
+ - Store configuration and settings
20
+ - Default buyer groups (associated with Accounts)
21
+ - Entitlement policies (who can see which products)
22
+ - Pricing policies and price book mappings
23
+ - Payment gateway configuration (Stripe, Adyen, etc.)
24
+ - Tax provider configuration (Avalara, Vertex, manual)
25
+ - Shipping methods and configurations
26
+ - Product catalog associations
27
+ - Inventory locations
28
+ - Search index configurations
29
+
30
+ **Where it lives:**
31
+ - Data records in standard Commerce objects:
32
+ - `WebStore` - Store settings and configuration
33
+ - `BuyerGroup` - Account-based buyer segments
34
+ - `EntitlementPolicy` - Product visibility rules
35
+ - `CommerceEntitlementProduct` - Product-policy associations
36
+ - `ProductCatalog` - Catalog definitions
37
+ - `Pricebook2` - Price books
38
+ - Additional payment, tax, shipping records
39
+
40
+ **How to create:**
41
+ - Via UI: Setup → Commerce → Stores
42
+ - Cannot be created via Metadata API
43
+ - Cannot be deployed via `sf project deploy`
44
+
45
+ ---
46
+
47
+ ### 2. Storefront (Frontend Metadata)
48
+
49
+ **What it is:**
50
+ - Digital Experience (LWR site) for buyer-facing shopping experience
51
+ - Source-controllable as ExperienceBundle metadata
52
+ - Created automatically when you create a Commerce Store
53
+
54
+ **What it includes:**
55
+ - ExperienceBundle metadata (`StorefrontName.digitalExperience-meta.xml`)
56
+ - URL routing configuration (`sfdc_cms__route`)
57
+ - Page definitions (`sfdc_cms__view`)
58
+ - Homepage
59
+ - Product List Pages (PLP)
60
+ - Product Detail Pages (PDP)
61
+ - Shopping cart
62
+ - Checkout flow
63
+ - Order confirmation
64
+ - Search results
65
+ - Lightning Web Components (product cards, cart components, checkout)
66
+ - Branding and theme configuration (`sfdc_cms__brandingSet`, `sfdc_cms__theme`)
67
+ - Page layouts (`sfdc_cms__themeLayout`)
68
+ - Navigation structure
69
+ - Custom LWCs for extensions
70
+
71
+ **Where it lives:**
72
+ - `force-app/main/default/digitalExperiences/site/StorefrontName/`
73
+ - Example: `force-app/main/default/digitalExperiences/site/My_B2B_Store1/`
74
+
75
+ **How to create:**
76
+ - Automatically generated by Commerce Store setup wizard
77
+ - Retrieved from org using Salesforce CLI
78
+ - Cannot be manually created from scratch
79
+
80
+ **How to deploy:**
81
+ - Retrievable: `sf project retrieve start -m DigitalExperienceBundle:site/<name>`
82
+ - Deployable: `sf project deploy start -m DigitalExperienceBundle`
83
+ - Source-controllable in Git
84
+
85
+ ---
86
+
87
+ ## Why You Cannot Create Storefront Metadata from Scratch
88
+
89
+ ### Technical Reasons
90
+
91
+ 1. **Complex Dependency Chain**
92
+ - Create merchandisers store
93
+ - Create DigitalExperienceBundle
94
+ - Integrate both together
95
+
96
+ 2. **Hundreds of Auto-Generated Configurations**
97
+ - Component IDs and region IDs (UUIDs)
98
+ - WebStore associations
99
+ - Commerce-managed component configurations
100
+ - Default routing rules
101
+ - Search configurations
102
+ - Cart and checkout flow definitions
103
+ - Payment integration settings
104
+
105
+ 3. **Commerce-Managed Components**
106
+ - Product List Page (PLP) components
107
+ - Product Detail Page (PDP) components
108
+ - Cart components
109
+ - Checkout components
110
+ - Search components
111
+ - These require specific configurations from Store data
112
+
113
+ 4. **Metadata API Limitation**
114
+ - Metadata API deploys metadata types (Apex, LWCs, objects)
115
+ - Metadata API CANNOT create SObject data (WebStore records)
116
+ - Store creation requires data operations, not metadata operations
117
+
118
+ ---
119
+
120
+ ## The Required Creation Order
121
+
122
+ ### Step 1: Create Commerce Store (Must Be First)
123
+
124
+ ```
125
+ User Interface (Commerce App)
126
+
127
+ WebStore Record Created
128
+
129
+ BuyerGroup Records Created
130
+
131
+ EntitlementPolicy Records Created
132
+
133
+ Digital Experience Auto-Generated
134
+
135
+ Commerce Components Configured
136
+ ```
137
+
138
+ **Why this must be first:**
139
+ - Generates WebStore record with unique ID
140
+ - Creates default configurations
141
+ - Auto-generates associated Digital Experience
142
+ - Configures Commerce component relationships
143
+ - Sets up default buyer access rules
144
+
145
+ ### Step 2: Retrieve Storefront Metadata
146
+
147
+ ```
148
+ sf org list metadata --metadata-type DigitalExperienceConfig
149
+
150
+ Select Store from List
151
+
152
+ sf project retrieve start -m DigitalExperienceBundle:site/<name>
153
+
154
+ Metadata Saved to Local Repository
155
+
156
+ Now Editable and Source-Controllable
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Key Takeaway
162
+
163
+ **Commerce B2B = Store (data) + Storefront (metadata)**
164
+
165
+ 1. Create Store → generates Storefront
166
+ 2. Retrieve Storefront → customize and version control if needed
167
+ 3. Deploy Storefront → only after creating Store in target org
168
+
169
+ **Never skip the Store creation. Never create Storefront metadata from scratch.**
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: deploying-ui-bundle
3
+ description: "Deploy a Salesforce UI bundle to an org — the full deployment sequence including org authentication, pre-deploy build, metadata deployment, permission set assignment, data import, GraphQL schema fetch, and codegen. Use whenever the user wants to deploy, push to org, assign permission sets, import data, fetch GraphQL schema, run codegen, or set up an org after development. Triggers on: deploy, push to org, deploy metadata, assign permission set, import data, schema fetch, codegen, org auth, authenticate org, build and deploy, post-deploy, org setup."
4
+ ---
5
+
6
+ # Deploying a UI Bundle
7
+
8
+ The order of operations is critical when deploying to a Salesforce org. This sequence reflects the canonical flow.
9
+
10
+ ## Step 1: Org Authentication
11
+
12
+ Check if the org is connected. If not, authenticate. All subsequent steps require an authenticated org.
13
+
14
+ ## Step 2: Pre-deploy UI Bundle Build
15
+
16
+ Install dependencies and build the UI bundle to produce `dist/`. Required before deploying UI bundle entities.
17
+
18
+ Run when: deploying UI bundles and `dist/` is missing or source has changed.
19
+
20
+ ## Step 3: Deploy Metadata
21
+
22
+ Check for a manifest (`manifest/package.xml` or `package.xml`) first. If present, deploy using the manifest. If not, deploy all metadata from the project.
23
+
24
+ Deploys objects, layouts, permission sets, Apex classes, UI bundles, and all other metadata. Must complete before schema fetch — the schema reflects org state.
25
+
26
+ ## Step 4: Post-deploy Configuration
27
+
28
+ Deploying does not mean assigning. After deployment:
29
+
30
+ - **Permission sets / groups** — assign to users so they have access to custom objects and fields. Required for GraphQL introspection to return the correct schema.
31
+ - **Profiles** — ensure users have the correct profile.
32
+ - **Other config** — named credentials, connected apps, custom settings, flow activation.
33
+
34
+ Proactive behavior: after a successful deploy, discover permission sets in `force-app/main/default/permissionsets/` and assign each one (or ask the user).
35
+
36
+ ## Step 5: Data Import (optional)
37
+
38
+ Only if `data/data-plan.json` exists. Delete runs in reverse plan order (children before parents). Import uses Anonymous Apex with duplicate rule save enabled.
39
+
40
+ Always ask the user before importing or cleaning data.
41
+
42
+ ## Step 6: GraphQL Schema and Codegen
43
+
44
+ 1. Set default org
45
+ 2. Fetch schema (GraphQL introspection) — writes `schema.graphql` at project root
46
+ 3. Generate types (codegen reads schema locally)
47
+
48
+ Run when: schema missing, or metadata/permissions changed since last fetch.
49
+
50
+ ## Step 7: Final UI Bundle Build
51
+
52
+ Build the UI bundle if not already done in Step 2.
53
+
54
+ ## Summary: Interaction Order
55
+
56
+ 1. Check/authenticate org
57
+ 2. Build UI bundle (if deploying UI bundles)
58
+ 3. Deploy metadata
59
+ 4. Assign permissions and configure
60
+ 5. Import data (if data plan exists, with user confirmation)
61
+ 6. Fetch GraphQL schema and run codegen
62
+ 7. Build UI bundle (if needed)
63
+
64
+ ## Critical Rules
65
+
66
+ - Deploy metadata **before** fetching schema — custom objects/fields appear only after deployment
67
+ - Assign permissions **before** schema fetch — the user may lack FLS for custom fields
68
+ - Re-run schema fetch and codegen **after every metadata deployment** that changes objects, fields, or permissions
69
+ - Never skip permission set assignment or data import silently — either run them or ask the user
70
+
71
+ ## Post-deploy Checklist
72
+
73
+ After every successful metadata deploy:
74
+
75
+ 1. Discover and assign permission sets (or ask the user)
76
+ 2. If `data/data-plan.json` exists, ask the user about data import
77
+ 3. Re-run schema fetch and codegen from the UI bundle directory
@@ -0,0 +1,30 @@
1
+ # Credits & Acknowledgments
2
+
3
+ This skill was influenced by the [sf-skills](https://github.com/Jaganpro/sf-skills) repository and built upon the collective wisdom of the Salesforce developer community. We gratefully acknowledge the following authors and resources whose ideas, patterns, and best practices have shaped this skill.
4
+
5
+ ---
6
+
7
+ ## Authors & Contributors
8
+
9
+ ### Jag Valaiyapathy (**[Jaganpro)](https://github.com/Jaganpro)**
10
+
11
+ **[sf-skills](https://github.com/Jaganpro/sf-skills)**
12
+
13
+ Key contributions influencing this skill:
14
+
15
+ - Pioneering open-source Salesforce skills for agentic coding tools
16
+ - Apex code generation and review patterns
17
+ - Best practices, anti-patterns, and design patterns reference material
18
+ - Template library for common Apex class types
19
+
20
+ This skill was influenced by the [sf-skills](https://github.com/Jaganpro/sf-skills) repository.
21
+
22
+ ---
23
+
24
+ ## Special Thanks
25
+
26
+ To the entire Salesforce developer community for sharing knowledge, writing blogs, creating open-source tools, and helping each other build better solutions.
27
+
28
+ ---
29
+
30
+ *If we've missed anyone whose work influenced these skills, please let us know so we can add proper attribution.*
@@ -0,0 +1,399 @@
1
+ ---
2
+ name: generating-apex
3
+ description: Primary Apex authoring skill for class generation, refactoring, and review. ALWAYS ACTIVATE when the user mentions Apex, .cls, triggers, or asks to create/refactor a class (service, selector, domain, batch, queueable, schedulable, invocable, DTO, utility, interface, abstract, exception, REST resource). Use this skill for requests involving SObject CRUD, mapping collections, fetching related records, scheduled jobs, batch jobs, trigger design, @AuraEnabled controllers, @RestResource endpoints, custom REST APIs, or code review of existing Apex.
4
+ ---
5
+
6
+ # Generating Apex
7
+
8
+ Use this skill for production-grade Apex: new classes, selectors, services, async jobs,
9
+ invocable methods, and triggers; and for evidence-based review of existing `.cls`.
10
+
11
+ ## Required Inputs
12
+
13
+ Gather or infer before authoring:
14
+
15
+ - Class type (service, selector, domain, batch, queueable, schedulable, invocable, trigger, trigger action, DTO, utility, interface, abstract, exception, REST resource)
16
+ - Target object(s) and business goal
17
+ - Class name (derive using the naming table below)
18
+ - Net-new vs refactor/fix; any org/API constraints
19
+ - Deployment targets
20
+
21
+ Defaults unless specified:
22
+ - Sharing: `with sharing` (see sharing rules per type below)
23
+ - Access: `public` (use `global` only when required by managed packages or `@InvocableMethod`)
24
+ - API version: `66.0` (minimum version)
25
+ - ApexDoc comments: yes
26
+
27
+ If the user provides a clear, complete request, generate immediately without unnecessary back-and-forth.
28
+
29
+ ---
30
+
31
+ ## Workflow
32
+
33
+ All steps are sequential. Do not skip, merge, or reorder. If blocked, stop and ask for missing context. If not applicable, mark `N/A` with a one-line justification in the report.
34
+
35
+ ### Phase 1 — Author
36
+
37
+ 1. **Discover project conventions**
38
+ - Service-Selector-Domain layering, logging utilities
39
+ - Existing classes/triggers and current trigger framework or handler pattern
40
+ - Whether Trigger Actions Framework (TAF) is already in use
41
+
42
+ 2. **Choose the smallest correct pattern** (see Type-Specific Guidance below)
43
+
44
+ 3. **Review templates and assets**
45
+ - Read the matching template from `assets/` before authoring (see Type-Specific Guidance for the file mapping)
46
+ - When a `references/` example exists for the type, read it as a concrete style guide
47
+ - For any test class work, always read and use `generating-apex-test` skill
48
+
49
+ 4. **Author with guardrails** -- apply every rule in the Rules section below
50
+ - Generate `{ClassName}.cls` with ApexDoc
51
+ - Generate `{ClassName}.cls-meta.xml`
52
+
53
+ 5. **Generate test classes** -- delegate to `generating-apex-test` to create `{ClassName}Test.cls` and `{ClassName}Test.cls-meta.xml`. Do not write test code in this skill. If the test skill is unavailable, record `test_skill=unavailable: <reason>` in Step 8.
54
+
55
+ ### Phase 2 — Validate (required before reporting)
56
+
57
+ Writing files is the midpoint, not the finish line. Steps 6 and 7 each require a tool invocation and produce output that must appear in the Step 8 report. Do not summarize or present the report until both steps have run and their output is captured.
58
+
59
+ 6. **Run code analyzer**
60
+ - Invoke MCP `run_code_analyzer` on all generated/updated `.cls` files.
61
+ - Remediate all `sev0`, `sev1`, and `sev2` violations; re-run until clean.
62
+ - Capture the final tool output verbatim for the report.
63
+ - Fallback: `sf code-analyzer run --target <target>`. If both are unavailable, record `run_code_analyzer=unavailable: <error>` in the report.
64
+
65
+ 7. **Execute Apex tests**
66
+ - Run org tests including `{ClassName}Test` via `sf apex run test` or MCP.
67
+ - Delegate all test fixes/coverage work to `generating-apex-test`; iterate until green.
68
+ - Capture pass/fail counts and coverage percentage for the report.
69
+ - If unavailable, record `test_execution=unavailable: <error>` in the report.
70
+
71
+ ### Phase 3 — Report
72
+
73
+ 8. **Report** -- use the output format at the bottom of this file.
74
+ - The `Analyzer` line must contain the actual Step 6 tool output (or `run_code_analyzer=unavailable: <reason>` after attempting invocation).
75
+ - The `Testing` line must contain the actual Step 7 results (or `test_execution=unavailable: <reason>` after attempting invocation).
76
+ - A report missing either line is incomplete. Always attempt the tool invocation before recording unavailable.
77
+
78
+ ---
79
+
80
+ ## Rules
81
+
82
+ ### Hard-Stop Constraints (Must Enforce)
83
+
84
+ If any constraint would be violated in generated code, **stop and explain the problem** before proceeding:
85
+
86
+ | Constraint | Rationale |
87
+ |---|---|
88
+ | Place all SOQL outside loops | Avoid query governor limits (100 queries) |
89
+ | Place all DML outside loops | Avoid DML governor limits (150 statements) |
90
+ | Declare a sharing keyword on every class | Prevent unintended `without sharing` defaults and data exposure |
91
+ | Use Custom Metadata/Labels/describe calls instead of hardcoded IDs | Ensure portability across orgs |
92
+ | Always handle exceptions (log, rethrow, or recover) | Prevent silent failures |
93
+ | Use bind variables for all dynamic SOQL with user input | Prevent SOQL injection |
94
+ | Use Apex-native collections (`List`, `Map`, `Set`) rather than Java types | Prevent compile errors |
95
+ | Verify methods exist in Apex before use | Prevent reliance on non-existent APIs |
96
+ | Prefer structured logging over `System.debug()` | Debug string concatenation consumes CPU even when not observed |
97
+ | Never use `@future` methods | Use Queueable with `System.Finalizer`; `@future` cannot chain, cannot be called from Batch, and cannot accept non-primitive types |
98
+
99
+ ### Bulkification & Governor Limits
100
+
101
+ - All public APIs accept and process collections; single-record overloads delegate to the bulk method
102
+ - In batch/bulk flows, prefer partial-success DML (`Database.update(records, false)`) and process `SaveResult` for errors
103
+ - Use `Map<Id, SObject>` constructor for efficient ID-based lookups from query results
104
+ - Use `Map<Id, List<SObject>>` to group child records by parent; build the map in a single loop before processing
105
+ - Use `Set<Id>` for deduplication and membership checks; prefer `Set.contains()` over `List.contains()`
106
+ - Use relationship subqueries to fetch parent + child records in a single SOQL when both are needed
107
+ - Use `AggregateResult` with `GROUP BY` for rollup calculations instead of querying and counting in Apex
108
+ - Only DML records that actually changed — compare against `Trigger.oldMap` or prior state before adding to the update list
109
+ - Use `Limits.getQueries()`, `Limits.getDmlStatements()`, `Limits.getCpuTime()` to monitor consumption in complex transactions
110
+
111
+ ### SOQL Optimization
112
+
113
+ - Use selective queries with proper `WHERE` clauses; use indexed fields (`Id`, `Name`, `OwnerId`, lookup/master-detail fields, `ExternalId` fields, custom indexes) in filters when possible
114
+ - `SELECT *` does not exist in SOQL -- always specify the exact fields needed
115
+ - Apply `LIMIT` clauses to bound result sets; use `ORDER BY` for deterministic results
116
+ - When querying Custom Metadata Types (objects ending with `__mdt`), do NOT use SOQL — use the built-in methods (`{CustomMdt__mdt}.getAll().values()`, `getInstance()`, etc.)
117
+
118
+ ### Caching
119
+
120
+ - Use Platform Cache (`Cache.Org` / `Cache.Session`) for frequently accessed, rarely changed data; set a TTL and always handle cache misses — cache can be evicted at any time
121
+ - Use `private static Map` fields as transaction-scoped caches to prevent duplicate queries within the same execution context; lazy-initialize on first access
122
+
123
+ ### Security
124
+
125
+ - Default to `with sharing`; document justification for `without sharing` or `inherited sharing`
126
+ - `WITH USER_MODE` in SOQL and `AccessLevel.USER_MODE` for `Database` DML for CRUD/FLS enforcement
127
+ - Validate dynamic field/operator names via allowlist or `Schema.describe`
128
+ - Named Credentials for all external credentials/API keys
129
+ - `AuraHandledException` for `@AuraEnabled` user-facing errors (no internal details)
130
+ - `without sharing` requires a Custom Permission check
131
+ - Isolate `without sharing` logic in dedicated helper classes; call from `with sharing` entry points to limit elevated-access scope
132
+ - Encrypt PII/sensitive data at rest via Platform Encryption; never expose PII in debug statements, error messages, or API responses
133
+
134
+ ### Security Verification
135
+
136
+ Before finalizing, verify: CRUD/FLS enforced (SOQL + DML) · explicit sharing keyword on every class · no hardcoded secrets or Record IDs · PII excluded from logs and error messages · error messages sanitized for end users.
137
+
138
+ ### Error Handling
139
+
140
+ - Catch specific exceptions before generic `Exception`; include context in messages
141
+ - Use `try/catch` only around code that can throw (DML, callouts, JSON parsing, casts); avoid defensive wrapping of simple assignments/collection ops/arithmetic
142
+ - Preserve exception cause chains: `new CustomException('message', cause)` (do not replace stack trace with concatenated messages)
143
+ - Provide a custom exception class per service domain when meaningful
144
+ - In `@AuraEnabled` methods, catch exceptions and rethrow as `AuraHandledException`
145
+
146
+ ### Null Safety
147
+
148
+ - Add guard clauses for null/empty inputs at the top of every public method; match style to context: `return` early in private/trigger-handler methods, `throw` exceptions in public APIs, `record.addError()` in validation services
149
+ - Return empty collections instead of `null`
150
+ - Use safe navigation (`?.`) for chained property access
151
+ - Never dereference `map.get(key)` inline unless presence is guaranteed; use `containsKey`, assignment+null check, or safe navigation first
152
+ - Use null coalescing (`??`) for default values
153
+ - Prefer `String.isBlank(value)` over manual checks like `value == null || value.trim().isEmpty()`
154
+
155
+ ### Constants & Literals
156
+
157
+ - Use enums over string constants whenever possible; enum values follow `UPPER_SNAKE_CASE`
158
+ - Extract repeated literal strings/numbers into `private static final` constants or a constants class
159
+ - Use `Label.` custom labels for user-facing strings
160
+ - Use Custom Metadata for configurable values (thresholds, mappings, feature flags)
161
+ - Never output HTML-escaped entities in code (e.g., `&#39;`); use literal single quotes `'` in Apex string literals
162
+
163
+ ### Naming Conventions
164
+
165
+ | Type | Pattern | Example |
166
+ |---|---|---|
167
+ | Service | `{SObject}Service` | `AccountService` |
168
+ | Selector | `{SObject}Selector` | `AccountSelector` |
169
+ | Domain | `{SObject}Domain` | `OpportunityDomain` |
170
+ | Batch | `{Descriptive}Batch` | `AccountDeduplicationBatch` |
171
+ | Queueable | `{Descriptive}Queueable` | `ExternalSyncQueueable` |
172
+ | Schedulable | `{Descriptive}Schedulable` | `DailyCleanupSchedulable` |
173
+ | DTO | `{Descriptive}DTO` | `AccountMergeRequestDTO` |
174
+ | Wrapper | `{Descriptive}Wrapper` | `OpportunityLineWrapper` |
175
+ | Utility | `{Descriptive}Util` | `StringUtil` |
176
+ | Interface | `I{Descriptive}` | `INotificationService` |
177
+ | Abstract | `Abstract{Descriptive}` | `AbstractIntegrationService` |
178
+ | Exception | `{Descriptive}Exception` | `AccountServiceException` |
179
+ | REST Resource | `{SObject}RestResource` | `AccountRestResource` |
180
+ | Trigger | `{SObject}Trigger` | `AccountTrigger` |
181
+ | Trigger Action | `TA_{SObject}_{Action}` | `TA_Account_SetDefaults` |
182
+
183
+ Additional naming rules:
184
+ - Classes: `PascalCase`
185
+ - Methods: `camelCase`, start with a verb (`get`, `create`, `process`, `validate`, `is`, `has`, `can`)
186
+ - Variables: `camelCase`, descriptive nouns; Lists as plural nouns (e.g., `accounts`, `relatedContacts`); Maps as `{value}By{key}` (e.g., `accountsById`); Sets as `{noun}Ids`
187
+ - Constants: `UPPER_SNAKE_CASE`
188
+ - Use full descriptive names instead of abbreviations (`acc`, `tks`, `rec`)
189
+
190
+ ### ApexDoc
191
+
192
+ - Required on the class header and every `public`/`global` method
193
+ - Include: brief description, `@param`, `@return`, `@throws`, `@example` where helpful
194
+
195
+ Class-level format:
196
+
197
+ ```apex
198
+ /**
199
+ * @author Generated by Apex Skill
200
+ */
201
+ ```
202
+
203
+ Method-level format:
204
+
205
+ ```apex
206
+ /**
207
+ * @param paramName Description of the parameter
208
+ * @return Description of the return value
209
+ * @example
210
+ * List<Account> results = AccountService.deduplicateAccounts(accountIds);
211
+ */
212
+ ```
213
+
214
+ ### Code Structure & Architecture
215
+
216
+ - Single responsibility per class; max 500 lines -- split when exceeded
217
+ - Return Early: validate preconditions at method top, return/throw immediately
218
+ - Extract private helpers for methods over ~40 lines
219
+ - Use Dependency Injection (constructor/method params) for testability
220
+ - Prefer composition and narrow interfaces over deep inheritance; extend via new implementations, not modifications
221
+ - Enforce single-level abstraction per method across layer boundaries:
222
+
223
+ | Layer | Owns | Must NOT contain |
224
+ |---|---|---|
225
+ | Trigger | Event routing only | Business logic, orchestration |
226
+ | Handler/Service | Flow control, coordination | Inline SOQL/DML/HTTP/parsing |
227
+ | Domain | Business rules, validation | Queries, callouts, persistence details |
228
+ | Data/Integration | SOQL, DML, HTTP | Business decisions |
229
+
230
+ - Disallowed: methods mixing orchestration with inline SOQL/DML/HTTP; business rules mixed with parsing internals; validation + persistence + cross-system plumbing in one method
231
+
232
+ ---
233
+
234
+ ## Async Decision Matrix
235
+
236
+ | Scenario | Default | Key Traits |
237
+ |---|---|---|
238
+ | Standard async work | **Queueable** | Job ID, chaining, non-primitive types, configurable delay (up to 10 min via `AsyncOptions`), dedup signatures |
239
+ | Very large datasets | **Batch Apex** | Chunked processing, max 5 concurrent; use `QueryLocator` for large scopes |
240
+ | Modern batch alternative | **CursorStep** (`Database.Cursor`) | 2000-record chunks, higher throughput, no 5-job limit |
241
+ | Recurring schedule | **Scheduled Flow** (preferred) or **Schedulable** | Schedulable has 100-job limit; use only when chaining to Batch or needing complex Apex logic |
242
+ | Post-job cleanup | **Finalizer** (`System.Finalizer`) | Runs regardless of Queueable success/failure |
243
+ | Long-running callouts | **Continuation** | Up to 3 per transaction, 3 parallel |
244
+ | Delays > 10 minutes | `System.scheduleBatch()` | Schedule a Batch job at a specific future time |
245
+ | Legacy fire-and-forget | `@future` | **Do not use in new code** — see Hard-Stop Constraints; replace with Queueable + Finalizer |
246
+
247
+ ---
248
+
249
+ ## Type-Specific Guidance
250
+
251
+ ### Service
252
+ - Template: `assets/service.cls` · Reference: `references/AccountService.cls`
253
+ - `with sharing`; stateless — no `public` fields or mutable instance state; keep public APIs focused and `static` where reasonable
254
+ - Delegate all SOQL to Selectors and SObject behavior to Domains
255
+ - Wrap business errors in a custom exception (e.g., `AccountServiceException`)
256
+
257
+ ### Selector
258
+ - Template: `assets/selector.cls` · Reference: `references/AccountSelector.cls`
259
+ - `inherited sharing`; one per SObject or query domain
260
+ - Return `List<SObject>` or `Map<Id, SObject>`; use a shared base field list constant (no inline duplication)
261
+ - Accept filter parameters; always include `WITH USER_MODE`
262
+
263
+ ### Domain
264
+ - Template: `assets/domain.cls`
265
+ - `with sharing`; encapsulate field defaults, derivations, and validations
266
+ - Operate on in-memory lists only; no SOQL/DML (belongs in Services/Selectors)
267
+
268
+ ### Batch
269
+ - Template: `assets/batch.cls` · Reference: `references/AccountDeduplicationBatch.cls`
270
+ - `with sharing`; implement `Database.Batchable<SObject>` (add `Database.Stateful` when tracking across chunks)
271
+ - `start()` = query definition; `execute()` = business logic; `finish()` = logging/notification
272
+ - Use `QueryLocator` for large datasets; handle partial failures via `Database.SaveResult`
273
+ - Accept filter parameters via constructor for reusability
274
+
275
+ ### Queueable
276
+ - Template: `assets/queueable.cls`
277
+ - `with sharing`; implement `Queueable` and optionally `Database.AllowsCallouts` when HTTP callouts are needed
278
+ - Accept data via constructor
279
+ - Add chain-depth guards to prevent infinite chains
280
+ - Optionally implement `Finalizer` for recovery/cleanup
281
+ - Use `AsyncOptions` for configurable delay (up to 10 min) and dedup signatures
282
+
283
+ ### Schedulable
284
+ - Template: `assets/schedulable.cls`
285
+ - `with sharing`; `execute()` delegates to Queueable or Batch
286
+ - Provide CRON constants and a convenience `scheduleDaily()` helper
287
+
288
+ ### DTO / Wrapper
289
+ - Template: `assets/dto.cls`
290
+ - No sharing keyword needed (pure data containers)
291
+ - Simple public properties; no-arg + parameterized constructors; `Comparable` when ordering matters
292
+ - Use `@JsonAccess` on private/protected inner DTOs that are serialized/deserialized
293
+
294
+ ### Utility
295
+ - Template: `assets/utility.cls`
296
+ - No sharing keyword needed; all methods `public static`; `private` constructor
297
+ - Pure, side-effect-free; no SOQL/DML
298
+
299
+ ### Interface
300
+ - Template: `assets/interface.cls`
301
+ - Define clear contracts with ApexDoc on each method signature
302
+
303
+ ### Abstract
304
+ - Template: `assets/abstract.cls`
305
+ - `with sharing`; offer default behavior via `virtual` methods
306
+ - Mark extension points `protected virtual` or `protected abstract`
307
+ - Include a concrete example in the ApexDoc showing how to extend the class
308
+
309
+ ### Custom Exception
310
+ - Template: `assets/exception.cls`
311
+ - No sharing keyword; extend `Exception` with descriptive names
312
+ - Supported constructors: `()`, `('msg')`, `(cause)`, `('msg', cause)`
313
+
314
+ ### Trigger
315
+ - Template: `assets/trigger.cls`
316
+ - One trigger per object; delegate all logic to handler/TAF action classes
317
+ - Include all relevant DML contexts; if TAF: `new MetadataTriggerHandler().run();`
318
+
319
+ ### Trigger Action (TAF)
320
+ - One class per concern per context; implement `TriggerAction.{Context}`
321
+ - Register via `Trigger_Action__mdt` (actions are inactive without registration)
322
+ - Name: `TA_{SObject}_{ActionName}`; prefer field-value comparison over static booleans for recursion
323
+
324
+ ### Invocable Method (`@InvocableMethod`)
325
+ - Template: `assets/invocable.cls`
326
+ - `with sharing`; inner `Request`/`Response` with `@InvocableVariable`
327
+ - Method must be `public static`; non-static or single-object signatures will not compile
328
+ - Accept `List<Request>`, return `List<Response>`; bulkify (SOQL/DML outside loops)
329
+ - Decorator parameters: `label` (required — Flow Builder display name), `description`, `category` (groups actions in Builder), `callout=true` (required when method makes HTTP callouts)
330
+ - `@InvocableVariable` parameters: `label` (required), `description`, `required=true/false`
331
+ - `@InvocableVariable` supports: primitives, `Id`, `SObject`, `List<T>` only (no `Map`/`Set`/`Blob`); use `List<Id>` or `List<SObject>` fields for Flow collection I/O
332
+ - Always include `isSuccess`, `errorMessage`, and `errorType` (`e.getTypeName()`) in Response
333
+ - Return errors in Response (recommended); throwing an exception triggers the Flow Fault path — reserve for unrecoverable failures only
334
+
335
+ ### REST Resource (`@RestResource`)
336
+ - Template: `assets/rest-resource.cls`
337
+ - `global with sharing`; both class and methods must be `global`
338
+ - Versioned URL: `@RestResource(urlMapping='/{resource}/v1/*')`
339
+ - Use proper HTTP status codes per branch (`200`/`201`/`400`/`404`/`422`/`500`); never default all errors to `500`
340
+ - Validate inputs (Id format: `Pattern.matches('[a-zA-Z0-9]{15,18}', value)`); bind all user input in SOQL
341
+ - Include `LIMIT`/`ORDER BY` in queries; implement pagination (`pageSize`/`offset`)
342
+ - Standardized `ApiResponse` wrapper (`success`, `message`, `data`/`records`); inner request/response DTOs
343
+ - Thin controller: delegate business logic to Service classes
344
+
345
+ ### `@AuraEnabled` Controller
346
+ - `with sharing`; use `WITH USER_MODE` in all SOQL
347
+ - Use `@AuraEnabled(cacheable=true)` only for read-only queries; leave `cacheable` unset for DML operations
348
+ - Catch exceptions and rethrow as `AuraHandledException` with user-friendly messages
349
+
350
+ ---
351
+
352
+ ## Output Expectations
353
+
354
+ Deliverables per class:
355
+ - `{ClassName}.cls`
356
+ - `{ClassName}.cls-meta.xml` (default API version `66.0` or higher unless specified)
357
+ - `{ClassName}Test.cls` (generated via `generating-apex-test` skill)
358
+ - `{ClassName}Test.cls-meta.xml` (generated via `generating-apex-test` skill)
359
+
360
+ Meta XML template:
361
+
362
+ ```xml
363
+ <?xml version="1.0" encoding="UTF-8"?>
364
+ <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
365
+ <apiVersion>{API_VERSION}</apiVersion>
366
+ <status>Active</status>
367
+ </ApexClass>
368
+ ```
369
+
370
+ Report in this order:
371
+
372
+ ```text
373
+ Apex work: <summary>
374
+ Files: <paths>
375
+ Design: <pattern / framework choices>
376
+ Workflow: all steps completed (1-8); any N/A justified
377
+ Risks: <security, bulkification, async, dependency notes>
378
+ Analyzer: <REQUIRED -- paste actual run_code_analyzer output or state "run_code_analyzer=unavailable: <reason>">
379
+ Testing: <REQUIRED -- paste actual test execution results (pass/fail, coverage) or state "test_execution=unavailable: <reason>">
380
+ Deploy: <dry-run or next step>
381
+ ```
382
+
383
+ ---
384
+
385
+ ## Cross-Skill Integration
386
+
387
+ | Need | Delegate to |
388
+ |---|---|
389
+ | Apex tests / fix failures | `generating-apex-test` skill |
390
+ | Describe objects/fields | metadata skill (if available) |
391
+ | Deploy to org | deploy skill (if available) |
392
+ | Flow calling Apex | Flow skill (if available) |
393
+ | LWC calling Apex | LWC skill (if available) |
394
+
395
+ ---
396
+
397
+ ## Troubleshooting Boundary
398
+
399
+ This skill handles production `.cls`/`.trigger` issues only: compile/parse failures, deployment dependency errors, runtime governor-limit failures. For test execution, assertions, coverage, or `sf apex run test` failures, delegate to `generating-apex-test`.