@salesforce/afv-skills 1.17.0 → 1.18.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 (30) hide show
  1. package/package.json +1 -1
  2. package/skills/building-sf-integrations/SKILL.md +1 -1
  3. package/skills/configuring-code-analyzer/SKILL.md +482 -0
  4. package/skills/configuring-code-analyzer/examples/apex-project-config.yml +41 -0
  5. package/skills/configuring-code-analyzer/examples/ci-github-actions.yml +96 -0
  6. package/skills/configuring-code-analyzer/examples/fullstack-project-config.yml +46 -0
  7. package/skills/configuring-code-analyzer/examples/lwc-project-config.yml +26 -0
  8. package/skills/configuring-code-analyzer/references/ci-cd-templates.md +648 -0
  9. package/skills/configuring-code-analyzer/references/config-schema.md +257 -0
  10. package/skills/configuring-code-analyzer/references/diagnostic-flow.md +70 -0
  11. package/skills/configuring-code-analyzer/references/engine-prerequisites.md +276 -0
  12. package/skills/configuring-code-analyzer/references/rule-name-resolution.md +67 -0
  13. package/skills/configuring-code-analyzer/references/troubleshooting.md +298 -0
  14. package/skills/configuring-code-analyzer/scripts/check-prerequisites.sh +189 -0
  15. package/skills/configuring-code-analyzer/scripts/generate-config.sh +143 -0
  16. package/skills/configuring-code-analyzer/scripts/validate-config.sh +153 -0
  17. package/skills/managing-cdc-enablement/SKILL.md +164 -0
  18. package/skills/managing-cdc-enablement/assets/PlatformEventChannel-template.xml +5 -0
  19. package/skills/managing-cdc-enablement/assets/PlatformEventChannelMember-template.xml +11 -0
  20. package/skills/managing-cdc-enablement/references/deploy-troubleshooting.md +73 -0
  21. package/skills/managing-cdc-enablement/references/filter-expressions.md +93 -0
  22. package/skills/running-code-analyzer/SKILL.md +264 -267
  23. package/skills/running-code-analyzer/references/post-scan-workflows.md +286 -0
  24. package/skills/running-code-analyzer/scripts/describe-rule.js +382 -0
  25. package/skills/running-code-analyzer/scripts/list-rules.js +260 -0
  26. package/skills/running-code-analyzer/scripts/query-results.js +230 -0
  27. package/skills/using-salesforce-archive/SKILL.md +121 -0
  28. package/skills/using-salesforce-archive/examples/monitor-failed-jobs.md +47 -0
  29. package/skills/using-salesforce-archive/references/archive-activity-entity.md +59 -0
  30. package/skills/using-salesforce-archive/references/connect-api-operations.md +157 -0
@@ -0,0 +1,153 @@
1
+ #!/bin/bash
2
+ # validate-config.sh
3
+ # Validates a code-analyzer.yml configuration file.
4
+ # Usage: bash <skill_dir>/scripts/validate-config.sh [config-file]
5
+ #
6
+ # If no config file is specified, looks for code-analyzer.yml in current directory.
7
+ #
8
+ # Exit codes:
9
+ # 0 = Config is valid
10
+ # 1 = Config has errors
11
+
12
+ set -euo pipefail
13
+
14
+ CONFIG_FILE="${1:-code-analyzer.yml}"
15
+
16
+ echo "Validating: ${CONFIG_FILE}"
17
+ echo ""
18
+
19
+ # Check file exists
20
+ if [ ! -f "$CONFIG_FILE" ]; then
21
+ echo "ERROR: Config file not found: ${CONFIG_FILE}"
22
+ echo ""
23
+ echo "Expected locations:"
24
+ echo " - ./code-analyzer.yml"
25
+ echo " - ./code-analyzer.yaml"
26
+ echo ""
27
+ echo "Generate one with: sf code-analyzer config --output-file code-analyzer.yml"
28
+ exit 1
29
+ fi
30
+
31
+ # Check file is not empty
32
+ if [ ! -s "$CONFIG_FILE" ]; then
33
+ echo "ERROR: Config file is empty: ${CONFIG_FILE}"
34
+ exit 1
35
+ fi
36
+
37
+ # Basic YAML syntax check (if python3 available)
38
+ if command -v python3 &> /dev/null; then
39
+ echo "Checking YAML syntax..."
40
+ if python3 -c "
41
+ import yaml, sys
42
+ try:
43
+ with open('${CONFIG_FILE}', 'r') as f:
44
+ config = yaml.safe_load(f)
45
+ if config is None:
46
+ print('WARNING: Config file is empty or contains only comments')
47
+ sys.exit(0)
48
+ if not isinstance(config, dict):
49
+ print('ERROR: Config must be a YAML mapping (dictionary)')
50
+ sys.exit(1)
51
+ print('YAML syntax: OK')
52
+ except yaml.YAMLError as e:
53
+ print(f'ERROR: Invalid YAML syntax')
54
+ print(f' {e}')
55
+ sys.exit(1)
56
+ " 2>&1; then
57
+ echo ""
58
+ else
59
+ echo ""
60
+ echo "Fix YAML syntax errors before proceeding."
61
+ exit 1
62
+ fi
63
+ else
64
+ echo "WARNING: python3 not found — skipping YAML syntax validation (install python3 for full checks)"
65
+ fi
66
+
67
+ # Validate known field names
68
+ echo "Checking known fields..."
69
+ VALID_TOP_LEVEL="config_root log_folder log_level rules engines ignores suppressions"
70
+
71
+ if command -v python3 &> /dev/null; then
72
+ python3 -c "
73
+ import yaml, sys
74
+
75
+ with open('${CONFIG_FILE}', 'r') as f:
76
+ config = yaml.safe_load(f)
77
+
78
+ if config is None:
79
+ sys.exit(0)
80
+
81
+ valid_fields = set('${VALID_TOP_LEVEL}'.split())
82
+ unknown = set(config.keys()) - valid_fields
83
+ if unknown:
84
+ print(f'WARNING: Unknown top-level fields: {sorted(unknown)}')
85
+ print(' Valid fields: config_root, log_folder, log_level, rules, engines, ignores, suppressions')
86
+ else:
87
+ print('Known fields: OK')
88
+
89
+ # Check engines section
90
+ if 'engines' in config and config['engines']:
91
+ valid_engines = {'pmd', 'cpd', 'eslint', 'regex', 'retire-js', 'flow', 'sfge', 'apexguru'}
92
+ configured_engines = set(config['engines'].keys())
93
+ unknown_engines = configured_engines - valid_engines
94
+ if unknown_engines:
95
+ print(f'WARNING: Unknown engine names: {sorted(unknown_engines)}')
96
+ print(f' Valid engines: {sorted(valid_engines)}')
97
+ else:
98
+ print(f'Engines configured: {sorted(configured_engines)}')
99
+
100
+ # Check ignores section
101
+ if 'ignores' in config and config['ignores']:
102
+ if 'files' not in config['ignores']:
103
+ print('WARNING: ignores section should contain a \"files\" list')
104
+ elif not isinstance(config['ignores']['files'], list):
105
+ print('ERROR: ignores.files must be a list of glob patterns')
106
+ sys.exit(1)
107
+ else:
108
+ print(f'Ignore patterns: {len(config[\"ignores\"][\"files\"])} patterns configured')
109
+
110
+ # Check rules section
111
+ if 'rules' in config and config['rules']:
112
+ for engine, rules in config['rules'].items():
113
+ if rules and isinstance(rules, dict):
114
+ for rule_name, overrides in rules.items():
115
+ if overrides and isinstance(overrides, dict):
116
+ if 'severity' in overrides:
117
+ sev = overrides['severity']
118
+ valid_sevs = [1, 2, 3, 4, 5, 'Critical', 'High', 'Moderate', 'Low', 'Info']
119
+ if sev not in valid_sevs:
120
+ print(f'WARNING: rules.{engine}.{rule_name}.severity = {sev} (expected 1-5 or Critical/High/Moderate/Low/Info)')
121
+
122
+ print('')
123
+ " 2>&1
124
+ fi
125
+
126
+ # Run sf code-analyzer config validation (if sf CLI available)
127
+ echo ""
128
+ echo "Running Code Analyzer validation..."
129
+ if command -v sf &> /dev/null; then
130
+ if sf plugins --core 2>&1 | grep -qi "code-analyzer"; then
131
+ if sf code-analyzer config --config-file "$CONFIG_FILE" > /dev/null 2>&1; then
132
+ echo "Code Analyzer validation: PASSED"
133
+ echo ""
134
+ echo "Configuration is valid and ready to use."
135
+ exit 0
136
+ else
137
+ echo "Code Analyzer validation: FAILED"
138
+ echo ""
139
+ echo "Running with verbose output:"
140
+ sf code-analyzer config --config-file "$CONFIG_FILE" 2>&1 || true
141
+ exit 1
142
+ fi
143
+ else
144
+ echo "SKIP: Code Analyzer plugin not installed (cannot run full validation)"
145
+ echo "Install: sf plugins install @salesforce/plugin-code-analyzer"
146
+ fi
147
+ else
148
+ echo "SKIP: sf CLI not available (cannot run full validation)"
149
+ fi
150
+
151
+ echo ""
152
+ echo "Basic validation passed. Install Code Analyzer for full validation."
153
+ exit 0
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: managing-cdc-enablement
3
+ description: "Use to enable Salesforce Change Data Capture (CDC) on a standard or custom object, configure a custom event channel, set a filter expression, or add enrichment fields. TRIGGER broadly on any of: 'enable CDC', 'enable Change Data Capture', 'turn on CDC', 'subscribe X to change events', 'only emit events for', 'filter change events', 'enrich change events', 'create a custom event channel'; or any mention of CDC, change events, PlatformEventChannel, PlatformEventChannelMember, EnrichedField, ChangeEvents channel, enrichment fields, change event filter; or when the user wants a downstream system to receive Salesforce data changes; or when the user touches .platformEventChannelMember-meta.xml / .platformEventChannel-meta.xml files. SKIP when publishing platform events, Pub/Sub API or REST/SOAP (use building-sf-integrations), or ManagedEventSubscription (out of scope for CDC). Always use this skill for CDC channel-membership metadata."
4
+ metadata:
5
+ version: "1.0"
6
+ ---
7
+
8
+ # Managing Change Data Capture Enablement
9
+
10
+ Generate the metadata that subscribes Salesforce objects to Change Data Capture: `PlatformEventChannelMember` files for the default `ChangeEvents` channel or a custom channel, and `PlatformEventChannel` files for new custom channels. Covers enrichment fields, filter expressions, and the canonical naming and value formats that the Metadata API actually accepts (which differ from values that appear in many internal test fixtures and code-search hits).
11
+
12
+ ## Scope
13
+
14
+ - **In scope**: Generating `PlatformEventChannelMember` and `PlatformEventChannel` metadata for CDC. Subscribing standard objects, custom objects, or both. Configuring enrichment fields. Configuring filter expressions. Defining custom data channels.
15
+ - **Out of scope**: Publishing custom platform events (PE) — that's a different metadata type (`PlatformEvent`). Pub/Sub API or external Kafka/Bayeux configuration. Pricing/limits guidance — refer the user to the [CDC Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/). Programmatic event-bus subscribers in Apex.
16
+
17
+ ---
18
+
19
+ ## Clarifying Questions
20
+
21
+ Before generating, confirm with the user if not already clear:
22
+
23
+ - Which entity (or entities) need CDC enablement? Standard, custom, or both?
24
+ - Default channel (`ChangeEvents`) or a custom channel? If custom, what's the channel label?
25
+ - Any enrichment fields needed? (Lookup IDs that the consumer needs even when they didn't change.)
26
+ - Any filter expression needed? (A SOQL-WHERE-clause body that gates which change events emit.)
27
+
28
+ ---
29
+
30
+ ## Required Inputs
31
+
32
+ Gather or infer before proceeding:
33
+
34
+ - **Source entity API name(s)** — e.g. `Account`, `Lead`, `Order__c`. The skill internally translates this to the **ChangeEvent entity name** (see Workflow step 2).
35
+ - **Channel** — either `ChangeEvents` (default) or the developer name of a custom channel ending in `__chn`.
36
+ - **Enrichment fields (optional)** — list of field API names on the source object whose values should be included in every change event.
37
+ - **Filter expression (optional)** — a predicate over fields on the change event payload (e.g. `Status__c != null`).
38
+
39
+ Defaults unless specified:
40
+ - Channel: `ChangeEvents` (the default CDC channel — no path prefix).
41
+ - Enrichment fields: none.
42
+ - Filter expression: none.
43
+
44
+ If the user provides a clear, complete request, generate immediately without unnecessary back-and-forth.
45
+
46
+ ---
47
+
48
+ ## Workflow
49
+
50
+ All steps are sequential. Do not skip or reorder.
51
+
52
+ **Before generating anything, know the only valid CDC metadata types:** CDC is expressed entirely through `PlatformEventChannelMember` (one per subscribed entity) and `PlatformEventChannel` (only for custom channels). Do NOT use `<ChangeDataCapture>`, `.changeDataCapture-meta.xml`, `changeDataCapture/` directories, `EnableChangeDataCapture`, or `ManagedEventSubscription` — these are not in scope for CDC. If you find yourself writing any of them, stop and use a `PlatformEventChannelMember` file instead.
53
+
54
+ 1. **Identify the channel** — if the user names a custom channel, you'll generate a `PlatformEventChannel` file (see step 4). Otherwise use the literal value `ChangeEvents` for the default channel.
55
+
56
+ 2. **Translate source entity to ChangeEvent entity name** — `<selectedEntity>` is the **ChangeEvent** type, NOT the source object:
57
+
58
+ | Source object | `<selectedEntity>` value |
59
+ |---|---|
60
+ | `Account` | `AccountChangeEvent` |
61
+ | `Lead` | `LeadChangeEvent` |
62
+ | `Contact` | `ContactChangeEvent` |
63
+ | `Order__c` (custom) | `Order__ChangeEvent` |
64
+ | `MyThing__c` (custom) | `MyThing__ChangeEvent` |
65
+
66
+ For standard objects: append `ChangeEvent`. For custom objects: replace the trailing `__c` with `__ChangeEvent` (the double-underscore is preserved).
67
+
68
+ 3. **Generate the channel-member file** — one file per `(entity, channel)` pair. **The filename and fullName always use a SINGLE underscore between the entity stem and `ChangeEvent`** — this is independent of how `selectedEntity` is formatted in the XML body. For custom objects, drop the `__c` from the source name when forming the filename:
69
+
70
+ | Source object | Filename (and fullName) | `<selectedEntity>` (in XML) |
71
+ |---|---|---|
72
+ | `Account` | `Account_ChangeEvent.platformEventChannelMember-meta.xml` | `AccountChangeEvent` |
73
+ | `Lead` | `Lead_ChangeEvent.platformEventChannelMember-meta.xml` | `LeadChangeEvent` |
74
+ | `Order__c` | `Order_ChangeEvent.platformEventChannelMember-meta.xml` (NOT `Order__ChangeEvent`) | `Order__ChangeEvent` |
75
+ | `MyThing__c` | `MyThing_ChangeEvent.platformEventChannelMember-meta.xml` (NOT `MyThing__ChangeEvent`) | `MyThing__ChangeEvent` |
76
+
77
+ The custom-object case is the easiest place to slip — the filename uses single underscore, the `selectedEntity` keeps its double underscore. Read `assets/PlatformEventChannelMember-template.xml` as the structural template.
78
+
79
+ 4. **For a custom channel**, generate a `PlatformEventChannel` file — required if any member references a non-default channel. Derive a DeveloperName from the user's label: strip spaces and non-alphanumeric characters, convert to CamelCase, then **always** append the literal suffix `__chn`. The filename and the channel's `<eventChannel>` reference must use this exact form, otherwise the deploy fails with `Invalid channel name`:
80
+
81
+ | User says | DeveloperName | Filename |
82
+ |---|---|---|
83
+ | `Partner Sync` | `PartnerSync__chn` | `PartnerSync__chn.platformEventChannel-meta.xml` (NOT `Partner_Sync...` or `PartnerSync...`) |
84
+ | `Order Updates` | `OrderUpdates__chn` | `OrderUpdates__chn.platformEventChannel-meta.xml` |
85
+ | `data sync` | `DataSync__chn` | `DataSync__chn.platformEventChannel-meta.xml` |
86
+
87
+ Members on this channel reference it by the same DeveloperName: `<eventChannel>PartnerSync__chn</eventChannel>`. Read `assets/PlatformEventChannel-template.xml`.
88
+
89
+ 5. **Add enrichment fields** if requested — repeat the `<enrichedFields><name>FIELD_API_NAME</name></enrichedFields>` block for each field. The name must be a **single-hop API name on the source entity** — verified working with: standard lookup IDs (`OwnerId`, `ParentId`), custom lookup fields (`MyLookup__c`), and custom non-relationship fields (`Region__c`, `Status__c`). Relationship traversals like `Owner.Name` or `Parent.Account.Industry` are rejected by deploy with "The selected field, X.Y, isn't valid".
90
+
91
+ 6. **Add a filter expression** if requested — wrap the predicate in `<filterExpression>...</filterExpression>`. The body is a WHERE-clause body without the `WHERE` keyword (e.g. `Status__c != null`, not `WHERE Status__c != null`). For supported operators, field types, and pitfalls, read `references/filter-expressions.md`.
92
+
93
+ ---
94
+
95
+ ## Rules / Constraints
96
+
97
+ | Constraint | Rationale |
98
+ |---|---|
99
+ | `<selectedEntity>` is the ChangeEvent type name, not the source object name | The Metadata API binds the member to a ChangeEvent entity — passing `Account` directly fails with "invalid event in selectedEntity". |
100
+ | Member fullName uses **single** underscore: `Account_ChangeEvent` | The double-underscore form (`Account__ChangeEvent`) is parsed as `<namespace>__<name>` and rejected: "Cannot create a new component with the namespace: Account". |
101
+ | Default channel value is exactly `ChangeEvents` — no path prefix | Older fixtures and some docs show `data/ChangeEvents`; the deploy returns "Unable to find the specified channel" for that value. |
102
+ | Enrichment field names are single-hop API names on the source entity | Standard (`OwnerId`), custom lookup (`MyLookup__c`), and custom non-relationship (`Region__c`) all validate. Traversals like `Owner.Name` are rejected: "The selected field, X.Y, isn't valid". |
103
+ | `<filterExpression>` body has no `WHERE` keyword | Deploy returns "filter expression has syntax errors: unexpected token: 'WHERE'". |
104
+ | Filter cannot reference `IsDeleted` or do relationship traversal (`Owner.Username`) | Deploy rejects with "field is invalid". |
105
+ | DateTime fields support **only equality** in filters (`=`, `!=`) — not `<` / `>` | Deploy returns "Only equality operators are supported for this field type or value". Use a named date literal: `LastModifiedDate = TODAY`. |
106
+ | Filter RHS must be a literal — no field-to-field comparison | `BillingCity = ShippingCity` returns "unexpected token: 'ShippingCity'". |
107
+ | Compound fields (e.g. `BillingAddress`) require dotted component access in filter | `BillingAddress.City = 'X'` deploys; flat `BillingCity` is rejected as "field is invalid"; raw `BillingAddress` is rejected as "has to be used with a component field". Note this is the OPPOSITE of `<enrichedFields>`, which uses flat names. |
108
+ | Custom channel filename ends with `__chn` before the meta-xml suffix | Salesforce's MDAPI naming convention; mismatch causes deploy ambiguity. |
109
+ | Custom channel XML must include `<channelType>data</channelType>` | Without `data`, the channel is rejected for CDC (other types exist for streaming/event channels). |
110
+ | Source custom objects must already exist (or be deployed in the same transaction) | The ChangeEvent entity for `Foo__c` doesn't exist until `Foo__c` does; member deploy fails otherwise. |
111
+ | Never generate a `PlatformEventChannel` file for the default `ChangeEvents` channel | The default channel is system-provided. Reference it via `<eventChannel>ChangeEvents</eventChannel>` on members, but only custom (`__chn`) channels need a channel-meta file. |
112
+ | `PlatformEventChannelMember` accepts ONLY four elements: `<enrichedFields>`, `<eventChannel>`, `<filterExpression>`, `<selectedEntity>` | Adding `<description>`, `<isActive>`, `<masterLabel>`, or any other element fails XML schema validation: "Element {...} invalid at this location". Stick to the four documented elements. |
113
+ | `PlatformEventChannel` accepts ONLY two elements: `<channelType>` and `<label>` | Adding `<masterLabel>`, `<description>`, etc. produces "Element {...}masterLabel invalid at this location in type PlatformEventChannel". Use `<label>`, not `<masterLabel>`. |
114
+ | Generated metadata files only — never run `sf project deploy start` from this skill | This skill produces artifacts; deployment is a separate lifecycle concern. |
115
+
116
+ ---
117
+
118
+ ## Gotchas
119
+
120
+ | Issue | Resolution |
121
+ |---|---|
122
+ | `Unable to find the specified channel` | Set `<eventChannel>ChangeEvents</eventChannel>` (no `data/` prefix). |
123
+ | `The PlatformEventChannelMember can't be created because it references an invalid event in the "selectedEntity" field` | Use the ChangeEvent name, not the source object: `AccountChangeEvent`, not `Account`. |
124
+ | `Cannot create a new component with the namespace: <Object>` | Rename the file to use a single underscore: `Account_ChangeEvent...`, not `Account__ChangeEvent...`. |
125
+ | `The selected field, X.Y, isn't valid` (in `<enrichedFields>`) | Replace `Owner.Name` with `OwnerId`. CDC enriches the lookup automatically; only single-hop field API names validate. |
126
+ | `filter expression has syntax errors: unexpected token: 'WHERE'` | Remove the `WHERE` keyword. The body is the predicate only. |
127
+ | `The BillingCity field in the filter expression is invalid` (or any flat Address component) | Use the compound dotted form: `BillingAddress.City`, not `BillingCity`. See `references/filter-expressions.md` for the full compound-field matrix. |
128
+ | Custom-object member fails with "ChangeEvent doesn't exist" | The source object isn't deployed yet. Ensure the `Foo__c` object metadata is in the same deploy or already in the org. |
129
+ | `DUPLICATE_VALUE` on second deploy | The member is already subscribed. Either delete first or skip — CDC doesn't support upsert on members directly. |
130
+ | `sf infra error (TypeInferenceError, DeployMetadata): Could not infer a metadata type` for a `.changeDataCapture-meta.xml` file | That file extension and metadata type don't exist. Replace the `changeDataCapture/<Entity>.changeDataCapture-meta.xml` file with a `platformEventChannelMembers/<Entity>_ChangeEvent.platformEventChannelMember-meta.xml` file. |
131
+ | User says "subscribe Order__c" but means standard `Order` | Confirm — `OrderChangeEvent` (standard) and `Order__ChangeEvent` (custom) are different entities. |
132
+
133
+ ---
134
+
135
+ ## Output Expectations
136
+
137
+ Deliverables:
138
+ - One `force-app/.../platformEventChannelMembers/<Entity>_ChangeEvent.platformEventChannelMember-meta.xml` per subscribed entity.
139
+ - One `force-app/.../platformEventChannels/<DevName>__chn.platformEventChannel-meta.xml` per custom channel (if any).
140
+
141
+ File structure follows the templates in `assets/`.
142
+
143
+ After receiving the generated files, the user can verify them with `sf project deploy start --dry-run -d <path> --target-org <alias>` before deploying. If a dry-run surfaces an unfamiliar error, `references/deploy-troubleshooting.md` maps the common deploy errors to their metadata-side fixes.
144
+
145
+ ---
146
+
147
+ ## Cross-Skill Integration
148
+
149
+ | Need | Delegate to |
150
+ |---|---|
151
+ | Generate the source custom object | `generating-custom-object` skill |
152
+ | Generate custom fields referenced by enrichment or filter | `generating-custom-field` skill |
153
+ | Build a permission set for users who consume change events | `generating-permission-set` skill |
154
+
155
+ ---
156
+
157
+ ## Reference File Index
158
+
159
+ | File | When to read |
160
+ |---|---|
161
+ | `assets/PlatformEventChannelMember-template.xml` | Step 3 — starting structure for a channel member |
162
+ | `assets/PlatformEventChannel-template.xml` | Step 4 — starting structure for a custom channel |
163
+ | `references/filter-expressions.md` | Step 6 — for the supported operators and field-type matrix when writing a filter expression |
164
+ | `references/deploy-troubleshooting.md` | When a user reports a dry-run deploy error and asks for help diagnosing it |
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <PlatformEventChannel xmlns="http://soap.sforce.com/2006/04/metadata">
3
+ <channelType>data</channelType>
4
+ <label>My Custom Channel</label>
5
+ </PlatformEventChannel>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <PlatformEventChannelMember xmlns="http://soap.sforce.com/2006/04/metadata">
3
+ <!-- Optional: add one <enrichedFields><name>FIELD_API_NAME</name></enrichedFields> per field. Single-hop API names only (e.g. OwnerId, ParentId, MyLookup__c, Region__c). -->
4
+
5
+ <!-- Default CDC channel: ChangeEvents (no path prefix). For a custom channel, use its DeveloperName, e.g. PartnerSync__chn. -->
6
+ <eventChannel>ChangeEvents</eventChannel>
7
+ <!-- Optional: add <filterExpression>YOUR_PREDICATE</filterExpression> if needed (predicate body only, no WHERE keyword). -->
8
+
9
+ <!-- ChangeEvent entity name. Standard: <Object>ChangeEvent. Custom: replace __c with __ChangeEvent. -->
10
+ <selectedEntity>AccountChangeEvent</selectedEntity>
11
+ </PlatformEventChannelMember>
@@ -0,0 +1,73 @@
1
+ # CDC Deploy Troubleshooting
2
+
3
+ Errors observed during real org dry-runs while authoring this skill, with the metadata-side fix.
4
+
5
+ ## "Unable to find the specified channel"
6
+
7
+ The `<eventChannel>` value doesn't match a channel known to the org.
8
+
9
+ - For the default channel, the value must be exactly `ChangeEvents`. NOT `data/ChangeEvents`, NOT `/data/ChangeEvents`, NOT `data/ChangeEvent`.
10
+ - For a custom channel, the value must match the channel's DeveloperName **including the `__chn` suffix** — e.g. `PartnerSync__chn`.
11
+ - If the custom channel is in the same deploy, ensure it's in the same package directory so MDAPI orders the deploy correctly.
12
+
13
+ ## "...invalid event in the 'selectedEntity' field"
14
+
15
+ `<selectedEntity>` must be the ChangeEvent entity, not the source object.
16
+
17
+ | Source | Wrong | Right |
18
+ |---|---|---|
19
+ | `Account` | `Account` | `AccountChangeEvent` |
20
+ | `Lead` | `Lead` | `LeadChangeEvent` |
21
+ | `Order__c` | `Order__c` | `Order__ChangeEvent` |
22
+ | `Custom__c` | `Custom__c` | `Custom__ChangeEvent` |
23
+
24
+ For custom objects, swap the trailing `__c` for `__ChangeEvent` — the double underscore separator is preserved.
25
+
26
+ ## "Cannot create a new component with the namespace: <Object>"
27
+
28
+ The member's fullName has two underscores between the entity and `ChangeEvent`. Salesforce parses `Foo__Bar` as `<namespace>__<name>` and rejects creation outside the org's own namespace.
29
+
30
+ - Member fullName format: `<Entity>_ChangeEvent` (single underscore).
31
+ - File name: `<Entity>_ChangeEvent.platformEventChannelMember-meta.xml`.
32
+
33
+ This applies even when the source object has `__c` — the member fullName drops the `__c` and uses single underscore: file `Order_ChangeEvent.platformEventChannelMember-meta.xml`, fullName `Order_ChangeEvent`.
34
+
35
+ ## "The selected field, X.Y, isn't valid" (enrichedFields)
36
+
37
+ Enrichment fields must be **single-hop API names on the source entity**. Field type doesn't matter — standard lookup IDs, custom lookups, and custom non-relationship fields all work. The rejection is specifically for relationship-traversal syntax (`X.Y`, `__r.Y`).
38
+
39
+ Verified working in dry-run:
40
+
41
+ | Field | Type | Result |
42
+ |---|---|---|
43
+ | `OwnerId` | standard lookup ID | ✓ deploys |
44
+ | `ParentId` | standard lookup ID | ✓ deploys |
45
+ | `MyAccountManager__c` | custom Lookup → User | ✓ deploys |
46
+ | `Region__c` | custom Text | ✓ deploys |
47
+ | `Status__c` | custom Picklist | ✓ deploys |
48
+
49
+ Verified rejected:
50
+
51
+ | Field | Why |
52
+ |---|---|
53
+ | `Owner.Name` | relationship traversal |
54
+ | `Parent.Account.Industry` | multi-hop traversal |
55
+ | `MyLookup__r.Name` | relationship traversal (custom) |
56
+
57
+ When the user says "include the owner's name in every event," the metadata stores `OwnerId` — CDC enriches the lookup automatically and the consumer resolves the related record from the ID.
58
+
59
+ ## "filter expression has syntax errors: unexpected token: 'WHERE'"
60
+
61
+ The body of `<filterExpression>` is a SOQL WHERE-clause body — without the `WHERE` keyword.
62
+
63
+ | Wrong | Right |
64
+ |---|---|
65
+ | `WHERE Status__c != null` | `Status__c != null` |
66
+ | `WHERE Industry IN ('Tech', 'Finance')` | `Industry IN ('Tech', 'Finance')` |
67
+
68
+ ## ChangeEvent entity doesn't exist (for custom objects)
69
+
70
+ `Foo__ChangeEvent` only exists if `Foo__c` exists. If both are being deployed in the same dry-run, the dry-run validator may flag the member because it validates entity references against the *current* org state, not the post-deploy state. Mitigations:
71
+
72
+ - Deploy the source object first, then the channel member in a second deploy.
73
+ - Or accept that dry-run will flag this case but a real (non-dry-run) deploy succeeds because MDAPI orders the components correctly.
@@ -0,0 +1,93 @@
1
+ # Filter Expression Reference
2
+
3
+ The `<filterExpression>` body is a SOQL-WHERE-clause-body — predicate only, no `WHERE` keyword. The platform supports a subset of SOQL grammar for CDC filters; this reference documents what the dry-run deploy verifies.
4
+
5
+ ## Operators by field type
6
+
7
+ | Field type | Supported operators | Notes |
8
+ |---|---|---|
9
+ | Text | `=`, `!=`, `IN`, `NOT IN`, `LIKE` | `LIKE` accepts `%` wildcard. Quote string literals with single quotes. |
10
+ | Number / Currency / Percent | `=`, `!=`, `<`, `<=`, `>`, `>=` | Numeric literals unquoted. |
11
+ | Boolean (Checkbox) | `=`, `!=` | Use `true` / `false` literal — no quotes. |
12
+ | Date | `=`, `!=` | Named literals (`TODAY`, `THIS_WEEK`, `LAST_N_DAYS:7`) and ISO date strings work. |
13
+ | DateTime | `=`, `!=` only | **Range operators (`>`, `<`) are rejected** — "Only equality operators are supported for this field type or value". |
14
+ | Reference (lookup ID) | `=`, `!=`, `IN`, `NOT IN` | Use the 18-character ID in single quotes: `OwnerId = '005000000000000AAA'`. |
15
+ | Picklist | `=`, `!=`, `IN`, `NOT IN` | Quote the value as a string. |
16
+
17
+ ## Compound expressions
18
+
19
+ `AND`, `OR`, and parentheses all work. There's no documented limit on nesting depth.
20
+
21
+ ```text
22
+ (Industry = 'Technology' OR Industry = 'Finance') AND AnnualRevenue > 0 AND Phone != null
23
+ ```
24
+
25
+ ## Null checks
26
+
27
+ ```text
28
+ Phone = null
29
+ Phone != null
30
+ ```
31
+
32
+ `null` is a literal — no quotes.
33
+
34
+ `ISBLANK()` and `ISNULL()` are **not** valid filter operators — they parse-fail with "unexpected token". They work in formulas but not in CDC filter expressions. Use `Field = null` / `Field != null` instead.
35
+
36
+ ## Functions
37
+
38
+ `LOWER(Name) = 'acme'` deploys successfully. Other SOQL functions probably work, but only `LOWER` has been verified in this skill's dataset. Test before relying on `UPPER`, `CONVERTCURRENCY`, etc.
39
+
40
+ ## What the filter cannot do
41
+
42
+ | Pattern | Deploy error |
43
+ |---|---|
44
+ | `WHERE Industry = 'Tech'` | "filter expression has syntax errors: unexpected token: 'WHERE'" — drop the keyword. |
45
+ | `IsDeleted = false` | "The IsDeleted field in the filter expression is invalid." Soft-deleted records still emit ChangeEvent; you cannot filter them out via this mechanism. |
46
+ | `Owner.Username = 'foo@bar.com'` | "The Owner.Username field in the filter expression is invalid." Relationship traversal works in `<enrichedFields>` rejection messages but NOT in filter expressions either — single-hop only. |
47
+ | `LastModifiedDate > LAST_N_DAYS:30` | "Only equality operators are supported for this field type or value." DateTime is equality-only; for "recent changes" semantics, use `LastModifiedDate = LAST_N_DAYS:N` (which compares to the *day*, not the timestamp). |
48
+
49
+ ## Field-to-field comparison: not supported
50
+
51
+ The right-hand side of a comparison must be a **literal**. Field references are rejected.
52
+
53
+ | Wrong | Deploy error |
54
+ |---|---|
55
+ | `BillingCity = ShippingCity` | "syntax errors: unexpected token: 'ShippingCity'" |
56
+ | `NumberOfEmployees > AnnualRevenue` | "unexpected token: 'AnnualRevenue'" |
57
+
58
+ If the user wants "records where two fields differ," that logic must live downstream of the change event consumer, not in the filter.
59
+
60
+ ## Composite (compound) fields like Address: dotted-component is the only valid form
61
+
62
+ Counterintuitively, the opposite rule applies for composite fields like `BillingAddress` vs. relationship traversals like `Owner.Name`. Compound fields **require** dot-notation; flat component names are rejected.
63
+
64
+ | Pattern | Result |
65
+ |---|---|
66
+ | `BillingAddress.City = 'San Francisco'` | ✓ deploys — required form for compound fields |
67
+ | `BillingAddress = null` | ✗ "Compound field BillingAddress has to be used with a component field in a filter expression" |
68
+ | `BillingCity = 'San Francisco'` (flat component) | ✗ "The BillingCity field in the filter expression is invalid" |
69
+ | `BillingState`, `BillingPostalCode`, `BillingCountry`, `BillingLatitude` (flat) | ✗ all rejected as invalid |
70
+
71
+ So, for the same `BillingAddress` field, the accepted form differs by location:
72
+
73
+ | Location | `BillingAddress` (compound) | `BillingAddress.City` (dotted) | `BillingCity` (flat component) |
74
+ |---|---|---|---|
75
+ | `<filterExpression>` | ✗ "has to be used with a component field" | ✓ deploys (required form) | ✗ "field is invalid" |
76
+ | `<enrichedFields>` | ✓ deploys | ✗ "isn't valid" (dots never allowed) | ✗ "isn't valid" (components not exposed at this layer) |
77
+
78
+ Rules per location:
79
+
80
+ - **Filter expression**: address components are reachable only via dotted form on the compound (`BillingAddress.City`). Both the compound itself (no component) and the flat component name are rejected.
81
+ - **Enrichment field**: takes a top-level field API name only. The compound `BillingAddress` is a top-level field and works; dotted forms are never valid here regardless of whether the dot would be a compound-component select or a relationship traversal; flat components like `BillingCity` are not top-level enrichable fields and are rejected.
82
+ - **Relationship traversal** (`Owner.Name`, `Parent.Industry`) is rejected in both locations.
83
+
84
+ The mental model: compound fields are a single physical column with sub-components; relationships are joins. The filter parser supports dotted access into compound sub-components but never into joins. The enrichment list takes top-level field names only and never accepts dots; the platform handles compound-vs-component decomposition itself when emitting the change event payload.
85
+
86
+ ## What's NOT yet verified
87
+
88
+ - Aggregate functions or subqueries — almost certainly unsupported.
89
+ - Operators on Long Text, Rich Text, Encrypted, Geolocation field types.
90
+ - Filter on a custom field that doesn't exist (deploy-time error vs runtime).
91
+ - Custom-object-specific picklist with locale-sensitive values.
92
+
93
+ If the user requests one of these and the deploy succeeds — update this file. If it fails — capture the error here.