Skip to content

Commit 7c4688d

Browse files
authored
@W-21788755 feat: Apex trigger skills UPDATE (#150)
1 parent 50dc84c commit 7c4688d

20 files changed

Lines changed: 22 additions & 30 deletions

skills/generating-apex-test/assets/test-class-template.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @description Test class for {ClassUnderTest}.
3-
* Tests bulk operations (251+ records), positive/negative paths,
4-
* and exception handling.
2+
* Test class for {ClassUnderTest}.
3+
* Tests bulk operations (251+ records), positive/negative paths,
4+
* and exception handling.
55
*/
66
@isTest
77
private class {ClassUnderTest}Test {

skills/generating-apex-test/references/assertion-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Assert.isTrue(accounts.size() > 0); // vague — use areEqual with exact count
2626
### Good: Descriptive message, tests specific behavior
2727

2828
```apex
29-
Assert.areEqual(true, result, 'Service should return true for valid input');
29+
Assert.isTrue(result, 'Service should return true for valid input');
3030
Assert.areEqual(200, accounts.size(), 'All 200 accounts should be processed');
3131
```
3232

skills/generating-apex-test/references/async-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void shouldExecuteFutureMethod() {
140140
Test.stopTest();
141141
142142
Account updated = [SELECT Id, Processed__c FROM Account WHERE Id = :acc.Id];
143-
Assert.areEqual(true, updated.Processed__c, 'Future should process record');
143+
Assert.isTrue(updated.Processed__c, 'Future should process record');
144144
}
145145
```
146146

skills/generating-apex/SKILL.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Primary Apex authoring skill for class generation, refactoring, and
66
# Generating Apex
77

88
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`.
1010

1111
## Required Inputs
1212

@@ -16,11 +16,11 @@ Gather or infer before authoring:
1616
- Target object(s) and business goal
1717
- Class name (derive using the naming table below)
1818
- Net-new vs refactor/fix; any org/API constraints
19-
- Deployment targets
19+
- Deployment targets (default to runSpecifiedTests and use generated tests where applicable)
2020

2121
Defaults unless specified:
2222
- 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`)
2424
- API version: `66.0` (minimum version)
2525
- ApexDoc comments: yes
2626

@@ -48,9 +48,9 @@ All steps are sequential. Do not skip, merge, or reorder. If blocked, stop and a
4848

4949
4. **Author with guardrails** -- apply every rule in the Rules section below
5050
- Generate `{ClassName}.cls` with ApexDoc
51-
- Generate `{ClassName}.cls-meta.xml`
51+
- Generate `{ClassName}.cls-meta.xml`
5252

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.
5454

5555
### Phase 2 — Validate (required before reporting)
5656

@@ -64,7 +64,7 @@ Writing files is the midpoint, not the finish line. Steps 6 and 7 each require a
6464

6565
7. **Execute Apex tests**
6666
- 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.
6868
- Capture pass/fail counts and coverage percentage for the report.
6969
- If unavailable, record `test_execution=unavailable: <error>` in the report.
7070

@@ -93,7 +93,7 @@ If any constraint would be violated in generated code, **stop and explain the pr
9393
| Use bind variables for all dynamic SOQL with user input | Prevent SOQL injection |
9494
| Use Apex-native collections (`List`, `Map`, `Set`) rather than Java types | Prevent compile errors |
9595
| 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 |
9797
| Never use `@future` methods | Use Queueable with `System.Finalizer`; `@future` cannot chain, cannot be called from Batch, and cannot accept non-primitive types |
9898

9999
### Bulkification & Governor Limits
@@ -142,6 +142,8 @@ Before finalizing, verify: CRUD/FLS enforced (SOQL + DML) · explicit sharing ke
142142
- Preserve exception cause chains: `new CustomException('message', cause)` (do not replace stack trace with concatenated messages)
143143
- Provide a custom exception class per service domain when meaningful
144144
- 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+
145147

146148
### Null Safety
147149

@@ -196,8 +198,9 @@ Class-level format:
196198

197199
```apex
198200
/**
199-
* @author Generated by Apex Skill
201+
* Provides services for geolocation and address conversion.
200202
*/
203+
public with sharing class GeolocationService { }
201204
```
202205

203206
Method-level format:
@@ -357,6 +360,10 @@ Deliverables per class:
357360
- `{ClassName}Test.cls` (generated via `generating-apex-test` skill)
358361
- `{ClassName}Test.cls-meta.xml` (generated via `generating-apex-test` skill)
359362

363+
Deliverables per trigger:
364+
- `{TriggerName}.trigger`
365+
- `{TriggerName}.trigger-meta.xml` (default API version `66.0` or higher unless specified)
366+
360367
Meta XML template:
361368

362369
```xml
@@ -396,4 +403,4 @@ Deploy: <dry-run or next step>
396403

397404
## Troubleshooting Boundary
398405

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`.

skills/generating-apex/assets/abstract.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
>>>>>>> Stashed changes
77
* Provides common behavior and defines extension points for subclasses.
88
* Subclasses must implement the abstract methods to provide specific behavior.
9-
* @author Generated by Apex Class Writer Skill
109
*
1110
* @example
1211
* // Extending this abstract class:

skills/generating-apex/assets/batch.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Batch Apex class for {describe the batch operation}.
33
* Processes {SObject} records in configurable batch sizes.
44
* Implements Database.Stateful to track cumulative results across chunks.
5-
* @author Generated by Apex Class Writer Skill
65
*
76
* @example
87
* // Execute with default batch size

skills/generating-apex/assets/domain.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Domain class for {SObject}.
33
* Encapsulates field-level defaults, derivations, and validations.
44
* Operates only on in-memory SObject data — no SOQL or DML.
5-
* @author Generated by Apex Class Writer Skill
65
*/
76
public with sharing class {SObject}Domain {
87

skills/generating-apex/assets/dto.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Data Transfer Object for {describe the data this DTO represents}.
33
* Used to pass structured data between layers without exposing SObjects.
44
* Serialization-friendly for use with JSON.serialize/deserialize and API responses.
5-
* @author Generated by Apex Class Writer Skill
65
*
76
* @example
87
* // Create from constructor

skills/generating-apex/assets/exception.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Custom exception for {describe when this exception is thrown}.
33
* Use this exception to signal domain-specific errors that callers
44
* can catch and handle distinctly from system exceptions.
5-
* @author Generated by Apex Class Writer Skill
65
*
76
* @example
87
* throw new {ClassName}('Account merge failed: duplicate detected.');

skills/generating-apex/assets/interface.cls

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* Interface for {describe the capability or contract this interface defines}.
33
* Implement this interface to provide {describe what implementations do}.
4-
* @author Generated by Apex Class Writer Skill
54
*
65
* @example
76
* public class EmailNotificationService implements {InterfaceName} {

0 commit comments

Comments
 (0)