You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: skills/generating-apex/SKILL.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ description: Primary Apex authoring skill for class generation, refactoring, and
6
6
# Generating Apex
7
7
8
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`.
9
+
invocable methods, and triggers; and for evidence-based review of existing `.cls` OR `.trigger`.
10
10
11
11
## Required Inputs
12
12
@@ -16,11 +16,11 @@ Gather or infer before authoring:
16
16
- Target object(s) and business goal
17
17
- Class name (derive using the naming table below)
18
18
- Net-new vs refactor/fix; any org/API constraints
19
-
- Deployment targets
19
+
- Deployment targets (default to runSpecifiedTests and use generated tests where applicable)
20
20
21
21
Defaults unless specified:
22
22
- Sharing: `with sharing` (see sharing rules per type below)
23
-
- Access: `public` (use `global` only when required by managed packages or `@InvocableMethod`)
23
+
- Access: `public` (use `global` only when required by managed packages or `@RestResource`)
24
24
- API version: `66.0` (minimum version)
25
25
- ApexDoc comments: yes
26
26
@@ -48,9 +48,9 @@ All steps are sequential. Do not skip, merge, or reorder. If blocked, stop and a
48
48
49
49
4.**Author with guardrails** -- apply every rule in the Rules section below
50
50
- Generate `{ClassName}.cls` with ApexDoc
51
-
- Generate `{ClassName}.cls-meta.xml`
51
+
- Generate `{ClassName}.cls-meta.xml`
52
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.
53
+
5.**Generate test classes** -- Load the skill `generating-apex-test` to create `{ClassName}Test.cls` and `{ClassName}Test.cls-meta.xml`. Apex tests are always required to be generated to deploy. No test file creation or edits can occur without loading the `generating-apex-test` skill to generate tests.
54
54
55
55
### Phase 2 — Validate (required before reporting)
56
56
@@ -64,7 +64,7 @@ Writing files is the midpoint, not the finish line. Steps 6 and 7 each require a
64
64
65
65
7.**Execute Apex tests**
66
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.
67
+
- Delegate all test generation/fixes/coverage work to `generating-apex-test`; iterate until the tests pass.
68
68
- Capture pass/fail counts and coverage percentage for the report.
69
69
- If unavailable, record `test_execution=unavailable: <error>` in the report.
70
70
@@ -93,7 +93,7 @@ If any constraint would be violated in generated code, **stop and explain the pr
93
93
| Use bind variables for all dynamic SOQL with user input | Prevent SOQL injection |
94
94
| Use Apex-native collections (`List`, `Map`, `Set`) rather than Java types | Prevent compile errors |
95
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|
96
+
|Avoid `System.debug()`in main code paths | Debug statements evaluate even when loggign is not active and consume CPU. Use a logging framework if required on main code paths|
97
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
98
99
99
### Bulkification & Governor Limits
@@ -142,6 +142,8 @@ Before finalizing, verify: CRUD/FLS enforced (SOQL + DML) · explicit sharing ke
142
142
- Preserve exception cause chains: `new CustomException('message', cause)` (do not replace stack trace with concatenated messages)
143
143
- Provide a custom exception class per service domain when meaningful
144
144
- In `@AuraEnabled` methods, catch exceptions and rethrow as `AuraHandledException`
145
+
- Fallback option: when no meaningful domain exception exists, catch generic `Exception` and either rethrow it or wrap it in a minimal custom exception that preserves the original cause.
146
+
145
147
146
148
### Null Safety
147
149
@@ -196,8 +198,9 @@ Class-level format:
196
198
197
199
```apex
198
200
/**
199
-
* @author Generated by Apex Skill
201
+
* Provides services for geolocation and address conversion.
200
202
*/
203
+
public with sharing class GeolocationService { }
201
204
```
202
205
203
206
Method-level format:
@@ -357,6 +360,10 @@ Deliverables per class:
357
360
-`{ClassName}Test.cls` (generated via `generating-apex-test` skill)
358
361
-`{ClassName}Test.cls-meta.xml` (generated via `generating-apex-test` skill)
359
362
363
+
Deliverables per trigger:
364
+
-`{TriggerName}.trigger`
365
+
-`{TriggerName}.trigger-meta.xml` (default API version `66.0` or higher unless specified)
366
+
360
367
Meta XML template:
361
368
362
369
```xml
@@ -396,4 +403,4 @@ Deploy: <dry-run or next step>
396
403
397
404
## Troubleshooting Boundary
398
405
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`.
406
+
This skill handles production `.cls`/`.trigger`/`.apex` 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`.
0 commit comments