Newer Version Available

This content describes an older version of this product. View Latest

Example: Add Event Enrichment Fields with Tooling API

To add event enrichment fields, use the PlatformEventChannelMember Tooling API object, and specify the fields, the channel, and channel member.

We provide Change Data Capture Enrichment to selected customers through a pilot program that requires agreement to specific terms and conditions. To be nominated to participate in the program, contact Salesforce. Pilot programs are subject to change, and we can’t guarantee acceptance. Change Data Capture Enrichment isn’t generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. We can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features. You can provide feedback and suggestions for Change Data Capture Enrichment in the Trailblazer Community.

Note

If the channel member you are enriching is part of a custom channel, create the custom channel first, as shown in this example. You can skip this step if using the ChangeEvents standard channel, or if you created the custom channel earlier.

Make a POST request to this REST endpoint:

1/services/data/v48.0/tooling/sobjects/PlatformEventChannel

Request body for the custom channel:

1{
2  "FullName": "SalesEvents__chn",
3  "Metadata": {
4    "channelType": "data",
5    "label": "Custom Channel for Sales App"
6  }
7}

To add enrichment fields, perform a REST request that creates a PlatformEventChannelMember component using Tooling API. In this example, the component contains two enriched fields in the enrichedFields array for AccountChangeEvent on the SalesEvents custom channel. External_Account_ID__c is a custom field defined in your org.

Make a POST request to this REST endpoint (API version 48.0 and later):

1/services/data/v48.0/tooling/sobjects/PlatformEventChannelMember

Request body with enrichment fields added in a channel member:

1{
2  "FullName": "SalesEvents_AccountChangeEvent",
3  "Metadata": {
4    "enrichedFields": [
5      {
6        "name": "External_Account_ID__c"
7      },
8      {
9        "name": "Industry"
10      }
11    ],
12    "eventChannel": "SalesEvents__chn",
13    "selectedEntity": "AccountChangeEvent"
14  }
15}

You can’t add a duplicate channel member. If the member is already part of the channel, you can update it to add enriched fields. First, get the channel member ID with this Tooling API query: SELECT Id,DeveloperName,EventChannel,SelectedEntity FROM PlatformEventChannelMember. Then make a PATCH request to this URI with the appended ID: /services/data/v48.0/tooling/sobjects/PlatformEventChannelMember/<ID>. Alternatively, you can delete the channel member and recreate it with the enriched fields. For more information, see PlatformEventChannelMember in the Tooling API Developer Guide.

Note

To find out which channel members and fields you configured, query the EnrichedField object in Tooling API. For example, this query returns the selected enriched field and the channel member ID.

1Select Field,ChannelMemberId FROM EnrichedField

In these query results, the first field is the enriched field and the second is the ID of the channel member. The custom field is returned as an ID.

1Industry,0v8RM00000000JsYAI
200NRM000001gEx32AE,0v8RM00000000JsYAI