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.

As a beta feature, Change Data Capture Enrichment is a preview and isn’t part of the “Services” under your master subscription agreement with Salesforce. Use this feature at your sole discretion, and make your purchase decisions only on the basis of generally available products and features. Salesforce doesn’t guarantee general availability of this feature within any particular time frame or at all, and we can discontinue it at any time. This feature is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it. All restrictions, Salesforce reservation of rights, obligations concerning the Services, and terms for related Non-Salesforce Applications and Content apply equally to your use of this feature. You can provide feedback and suggestions for Change Data Capture Enrichment in the Trailblazer Community. For information on enabling this feature in your org, contact Salesforce.

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/v49.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/v49.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