managing-cdc-enablement
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseManaging Change Data Capture Enablement
管理Change Data Capture启用配置
Generate the metadata that subscribes Salesforce objects to Change Data Capture: files for the default channel or a custom channel, and 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).
PlatformEventChannelMemberChangeEventsPlatformEventChannel生成用于将Salesforce对象订阅到Change Data Capture的元数据:针对默认通道或自定义通道的文件,以及针对新自定义通道的文件。涵盖enrichment fields、过滤表达式,以及Metadata API实际接受的标准命名和值格式(这些格式与许多内部测试 fixture 和代码搜索结果中的值不同)。
ChangeEventsPlatformEventChannelMemberPlatformEventChannelScope
范围
- In scope: Generating and
PlatformEventChannelMembermetadata for CDC. Subscribing standard objects, custom objects, or both. Configuring enrichment fields. Configuring filter expressions. Defining custom data channels.PlatformEventChannel - Out of scope: Publishing custom platform events (PE) — that's a different metadata type (). Pub/Sub API or external Kafka/Bayeux configuration. Pricing/limits guidance — refer the user to the CDC Developer Guide. Programmatic event-bus subscribers in Apex.
PlatformEvent
- 包含范围:为CDC生成和
PlatformEventChannelMember元数据。订阅标准对象、自定义对象或两者。配置enrichment fields。配置过滤表达式。定义自定义数据通道。PlatformEventChannel - 排除范围:发布自定义平台事件(PE)——这是不同的元数据类型()。Pub/Sub API或外部Kafka/Bayeux配置。定价/限制指南——请引导用户查看CDC开发者指南。Apex中的程序化事件总线订阅者。
PlatformEvent
Clarifying Questions
澄清问题
Before generating, confirm with the user if not already clear:
- Which entity (or entities) need CDC enablement? Standard, custom, or both?
- Default channel () or a custom channel? If custom, what's the channel label?
ChangeEvents - Any enrichment fields needed? (Lookup IDs that the consumer needs even when they didn't change.)
- Any filter expression needed? (A SOQL-WHERE-clause body that gates which change events emit.)
在生成之前,如果信息不明确,请与用户确认:
- 哪些实体需要启用CDC?标准对象、自定义对象还是两者都需要?
- 使用默认通道()还是自定义通道?如果是自定义通道,通道标签是什么?
ChangeEvents - 是否需要enrichment fields?(即使未发生变更,消费者仍需的查找ID。)
- 是否需要过滤表达式?(用于控制哪些变更事件会触发的SOQL WHERE子句主体。)
Required Inputs
必填输入
Gather or infer before proceeding:
- Source entity API name(s) — e.g. ,
Account,Lead. The skill internally translates this to the ChangeEvent entity name (see Workflow step 2).Order__c - Channel — either (default) or the developer name of a custom channel ending in
ChangeEvents.__chn - Enrichment fields (optional) — list of field API names on the source object whose values should be included in every change event.
- Filter expression (optional) — a predicate over fields on the change event payload (e.g. ).
Status__c != null
Defaults unless specified:
- Channel: (the default CDC channel — no path prefix).
ChangeEvents - Enrichment fields: none.
- Filter expression: none.
If the user provides a clear, complete request, generate immediately without unnecessary back-and-forth.
在继续之前,收集或推断以下信息:
- 源实体API名称——例如、
Account、Lead。此技能会在内部将其转换为ChangeEvent实体名称(请参阅工作流步骤2)。Order__c - 通道——(默认)或以
ChangeEvents结尾的自定义通道的开发者名称。__chn - Enrichment fields(可选)——源对象上的字段API名称列表,其值应包含在每个变更事件中。
- 过滤表达式(可选)——变更事件负载上的谓词(例如)。
Status__c != null
除非另有指定,否则默认值:
- 通道:(默认CDC通道——无前缀路径)。
ChangeEvents - Enrichment fields:无。
- 过滤表达式:无。
如果用户提供清晰、完整的请求,请立即生成,无需不必要的来回沟通。
Workflow
工作流
All steps are sequential. Do not skip or reorder.
Before generating anything, know the only valid CDC metadata types: CDC is expressed entirely through (one per subscribed entity) and (only for custom channels). Do NOT use , , directories, , or — these are not in scope for CDC. If you find yourself writing any of them, stop and use a file instead.
PlatformEventChannelMemberPlatformEventChannel<ChangeDataCapture>.changeDataCapture-meta.xmlchangeDataCapture/EnableChangeDataCaptureManagedEventSubscriptionPlatformEventChannelMember-
Identify the channel — if the user names a custom channel, you'll generate afile (see step 4). Otherwise use the literal value
PlatformEventChannelfor the default channel.ChangeEvents -
Translate source entity to ChangeEvent entity name —is the ChangeEvent type, NOT the source object:
<selectedEntity>Source object value<selectedEntity>AccountAccountChangeEventLeadLeadChangeEventContactContactChangeEvent(custom)Order__cOrder__ChangeEvent(custom)MyThing__cMyThing__ChangeEventFor standard objects: append. For custom objects: replace the trailingChangeEventwith__c(the double-underscore is preserved).__ChangeEvent -
Generate the channel-member file — one file perpair. The filename and fullName always use a SINGLE underscore between the entity stem and
(entity, channel)— this is independent of howChangeEventis formatted in the XML body. For custom objects, drop theselectedEntityfrom the source name when forming the filename:__cSource object Filename (and fullName) (in XML)<selectedEntity>AccountAccount_ChangeEvent.platformEventChannelMember-meta.xmlAccountChangeEventLeadLead_ChangeEvent.platformEventChannelMember-meta.xmlLeadChangeEventOrder__c(NOTOrder_ChangeEvent.platformEventChannelMember-meta.xml)Order__ChangeEventOrder__ChangeEventMyThing__c(NOTMyThing_ChangeEvent.platformEventChannelMember-meta.xml)MyThing__ChangeEventMyThing__ChangeEventThe custom-object case is the easiest place to slip — the filename uses single underscore, thekeeps its double underscore. ReadselectedEntityas the structural template.assets/PlatformEventChannelMember-template.xml -
For a custom channel, generate afile — 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
PlatformEventChannel. The filename and the channel's__chnreference must use this exact form, otherwise the deploy fails with<eventChannel>:Invalid channel nameUser says DeveloperName Filename Partner SyncPartnerSync__chn(NOTPartnerSync__chn.platformEventChannel-meta.xmlorPartner_Sync...)PartnerSync...Order UpdatesOrderUpdates__chnOrderUpdates__chn.platformEventChannel-meta.xmldata syncDataSync__chnDataSync__chn.platformEventChannel-meta.xmlMembers on this channel reference it by the same DeveloperName:. Read<eventChannel>PartnerSync__chn</eventChannel>.assets/PlatformEventChannel-template.xml -
Add enrichment fields if requested — repeat theblock for each field. The name must be a single-hop API name on the source entity — verified working with: standard lookup IDs (
<enrichedFields><name>FIELD_API_NAME</name></enrichedFields>,OwnerId), custom lookup fields (ParentId), and custom non-relationship fields (MyLookup__c,Region__c). Relationship traversals likeStatus__corOwner.Nameare rejected by deploy with "The selected field, X.Y, isn't valid".Parent.Account.Industry -
Add a filter expression if requested — wrap the predicate in. The body is a WHERE-clause body without the
<filterExpression>...</filterExpression>keyword (e.g.WHERE, notStatus__c != null). For supported operators, field types, and pitfalls, readWHERE Status__c != null.references/filter-expressions.md
所有步骤按顺序执行,请勿跳过或重新排序。
在生成任何内容之前,请了解唯一有效的CDC元数据类型:CDC完全通过(每个订阅实体一个)和(仅适用于自定义通道)来表示。请勿使用、、目录、或——这些不在CDC的范围内。如果发现自己正在编写这些内容,请停止并改用文件。
PlatformEventChannelMemberPlatformEventChannel<ChangeDataCapture>.changeDataCapture-meta.xmlchangeDataCapture/EnableChangeDataCaptureManagedEventSubscriptionPlatformEventChannelMember-
确定通道——如果用户指定了自定义通道,您需要生成文件(请参阅步骤4)。否则,对默认通道使用字面量值
PlatformEventChannel。ChangeEvents -
将源实体转换为ChangeEvent实体名称——是ChangeEvent类型,而非源对象:
<selectedEntity>源对象 值<selectedEntity>AccountAccountChangeEventLeadLeadChangeEventContactContactChangeEvent(自定义)Order__cOrder__ChangeEvent(自定义)MyThing__cMyThing__ChangeEvent对于标准对象:追加。对于自定义对象:将末尾的ChangeEvent替换为__c(保留双下划线)。__ChangeEvent -
生成通道成员文件——每个对对应一个文件。文件名和fullName始终在实体主干和
(实体, 通道)之间使用单个下划线——这与XML主体中ChangeEvent的格式无关。对于自定义对象,在形成文件名时去掉源名称中的<selectedEntity>:__c源对象 文件名(和fullName) (XML中)<selectedEntity>AccountAccount_ChangeEvent.platformEventChannelMember-meta.xmlAccountChangeEventLeadLead_ChangeEvent.platformEventChannelMember-meta.xmlLeadChangeEventOrder__c(不是Order_ChangeEvent.platformEventChannelMember-meta.xml)Order__ChangeEventOrder__ChangeEventMyThing__c(不是MyThing_ChangeEvent.platformEventChannelMember-meta.xml)MyThing__ChangeEventMyThing__ChangeEvent自定义对象的情况最容易出错——文件名使用单个下划线,保留双下划线。请阅读selectedEntity作为结构模板。assets/PlatformEventChannelMember-template.xml -
对于自定义通道,生成文件——如果任何成员引用非默认通道,则需要此文件。从用户提供的标签派生DeveloperName:去除空格和非字母数字字符,转换为驼峰式,然后始终追加字面量后缀
PlatformEventChannel。文件名和通道的__chn引用必须使用此确切形式,否则部署会失败并提示<eventChannel>:Invalid channel name用户表述 DeveloperName 文件名 Partner SyncPartnerSync__chn(不是PartnerSync__chn.platformEventChannel-meta.xml或Partner_Sync...)PartnerSync...Order UpdatesOrderUpdates__chnOrderUpdates__chn.platformEventChannel-meta.xmldata syncDataSync__chnDataSync__chn.platformEventChannel-meta.xml此通道上的成员通过相同的DeveloperName引用它:。请阅读<eventChannel>PartnerSync__chn</eventChannel>。assets/PlatformEventChannel-template.xml -
如果需要,添加enrichment fields——为每个字段重复块。名称必须是源实体上的单跳API名称——已验证可用于:标准查找ID(
<enrichedFields><name>FIELD_API_NAME</name></enrichedFields>、OwnerId)、自定义查找字段(ParentId)和自定义非关系字段(MyLookup__c、Region__c)。像Status__c或Owner.Name这样的关系遍历会在部署时被拒绝,提示“The selected field, X.Y, isn't valid”。Parent.Account.Industry -
如果需要,添加过滤表达式——将谓词包裹在中。主体是不带
<filterExpression>...</filterExpression>关键字的WHERE子句主体(例如WHERE,而非Status__c != null)。有关支持的运算符、字段类型和注意事项,请阅读WHERE Status__c != null。references/filter-expressions.md
Rules / Constraints
规则/约束
| Constraint | Rationale |
|---|---|
| The Metadata API binds the member to a ChangeEvent entity — passing |
Member fullName uses single underscore: | The double-underscore form ( |
Default channel value is exactly | Older fixtures and some docs show |
| Enrichment field names are single-hop API names on the source entity | Standard ( |
| Deploy returns "filter expression has syntax errors: unexpected token: 'WHERE'". |
Filter cannot reference | Deploy rejects with "field is invalid". |
DateTime fields support only equality in filters ( | Deploy returns "Only equality operators are supported for this field type or value". Use a named date literal: |
| Filter RHS must be a literal — no field-to-field comparison | |
Compound fields (e.g. | |
Custom channel filename ends with | Salesforce's MDAPI naming convention; mismatch causes deploy ambiguity. |
Custom channel XML must include | Without |
| Source custom objects must already exist (or be deployed in the same transaction) | The ChangeEvent entity for |
Never generate a | The default channel is system-provided. Reference it via |
| Adding |
| Adding |
Generated metadata files only — never run | This skill produces artifacts; deployment is a separate lifecycle concern. |
| 约束 | 理由 |
|---|---|
| Metadata API将成员绑定到ChangeEvent实体——直接传递 |
成员fullName使用单个下划线: | 双下划线形式( |
默认通道值恰好是 | 旧的fixture和一些文档显示 |
| Enrichment字段名称是源实体上的单跳API名称 | 标准字段( |
| 部署会返回“filter expression has syntax errors: unexpected token: 'WHERE'”。 |
过滤器不能引用 | 部署会拒绝并提示“field is invalid”。 |
DateTime字段在过滤器中仅支持相等性( | 部署会返回“Only equality operators are supported for this field type or value”。使用命名日期字面量: |
| 过滤器右侧必须是字面量——不支持字段间比较 | |
复合字段(例如 | |
自定义通道文件名在meta-xml后缀之前以 | Salesforce的MDAPI命名约定;不匹配会导致部署歧义。 |
自定义通道XML必须包含 | 如果没有 |
| 源自定义对象必须已存在(或在同一事务中部署) | |
永远不要为默认 | 默认通道是系统提供的。在成员上通过 |
| 添加 |
| 添加 |
仅生成元数据文件——切勿从此技能运行 | 此技能生成工件;部署是单独的生命周期问题。 |
Gotchas
常见问题
| Issue | Resolution |
|---|---|
| Set |
| Use the ChangeEvent name, not the source object: |
| Rename the file to use a single underscore: |
| Replace |
| Remove the |
| Use the compound dotted form: |
| Custom-object member fails with "ChangeEvent doesn't exist" | The source object isn't deployed yet. Ensure the |
| The member is already subscribed. Either delete first or skip — CDC doesn't support upsert on members directly. |
| That file extension and metadata type don't exist. Replace the |
User says "subscribe Order__c" but means standard | Confirm — |
| 问题 | 解决方案 |
|---|---|
| 设置 |
| 使用ChangeEvent名称,而非源对象: |
| 将文件重命名为使用单个下划线: |
| 将 |
| 删除 |
| 使用复合点分形式: |
| 自定义对象成员部署失败并提示“ChangeEvent doesn't exist” | 源对象尚未部署。确保 |
第二次部署时出现 | 成员已订阅。要么先删除,要么跳过——CDC不支持对成员直接进行upsert。 |
针对 | 该文件扩展名和元数据类型不存在。将 |
用户说“subscribe Order__c”但实际指标准 | 确认—— |
Output Expectations
输出预期
Deliverables:
- One per subscribed entity.
force-app/.../platformEventChannelMembers/<Entity>_ChangeEvent.platformEventChannelMember-meta.xml - One per custom channel (if any).
force-app/.../platformEventChannels/<DevName>__chn.platformEventChannel-meta.xml
File structure follows the templates in .
assets/After receiving the generated files, the user can verify them with before deploying. If a dry-run surfaces an unfamiliar error, maps the common deploy errors to their metadata-side fixes.
sf project deploy start --dry-run -d <path> --target-org <alias>references/deploy-troubleshooting.md交付物:
- 每个订阅实体对应一个文件。
force-app/.../platformEventChannelMembers/<Entity>_ChangeEvent.platformEventChannelMember-meta.xml - 每个自定义通道对应一个文件(如果有)。
force-app/.../platformEventChannels/<DevName>__chn.platformEventChannel-meta.xml
文件结构遵循中的模板。
assets/收到生成的文件后,用户可以在部署前使用验证它们。如果试运行出现不熟悉的错误,会将常见部署错误映射到元数据端的修复方法。
sf project deploy start --dry-run -d <path> --target-org <alias>references/deploy-troubleshooting.mdCross-Skill Integration
跨技能集成
| Need | Delegate to |
|---|---|
| Generate the source custom object | |
| Generate custom fields referenced by enrichment or filter | |
| Build a permission set for users who consume change events | |
| 需求 | 委托给 |
|---|---|
| 生成源自定义对象 | |
| 生成enrichment或过滤器引用的自定义字段 | |
| 为消费变更事件的用户生成权限集 | |
Reference File Index
参考文件索引
| File | When to read |
|---|---|
| Step 3 — starting structure for a channel member |
| Step 4 — starting structure for a custom channel |
| Step 6 — for the supported operators and field-type matrix when writing a filter expression |
| When a user reports a dry-run deploy error and asks for help diagnosing it |
| 文件 | 阅读时机 |
|---|---|
| 步骤3——通道成员的起始结构 |
| 步骤4——自定义通道的起始结构 |
| 步骤6——编写过滤表达式时,了解支持的运算符和字段类型矩阵 |
| 当用户报告试运行部署错误并请求帮助诊断时 |