Newer Version Available

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

Example: Add Event Enrichment Fields with Metadata API

To add event enrichment fields, use the PlatformEventChannelMember metadata type, and specify the fields, the channel, and channel member.

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.

This sample metadata component is for a custom channel.

1<?xml version="1.0" encoding="UTF-8"?>
2<PlatformEventChannel xmlns="http://soap.sforce.com/2006/04/metadata">
3    <channelType>data</channelType>
4    <label>Custom Channel for Sales Events</label>
5</PlatformEventChannel>

This package.xml references the previous definition. The custom channel name is SalesEvents__chn.

1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3    <types>
4        <members>SalesEvents__chn</members>
5        <name>PlatformEventChannel</name>
6    </types>
7    <version>63.0</version>
8</Package>

To add enrichment fields, deploy the PlatformEventChannelMember component containing the enriched fields. In this example, the component contains three enriched fields for AccountChangeEvent on the SalesEvents custom channel. Before you create this channel member, create a custom Text(20) field for Account with the label External Account ID.

1<?xml version="1.0" encoding="UTF-8"?>
2<PlatformEventChannelMember xmlns="http://soap.sforce.com/2006/04/metadata">
3    <enrichedFields>
4        <name>External_Account_ID__c</name>
5    </enrichedFields>
6    <enrichedFields>
7        <name>Industry</name>
8    </enrichedFields>
9    <enrichedFields>
10        <name>BillingAddress</name>
11    </enrichedFields>
12    <eventChannel>SalesEvents__chn</eventChannel>
13    <selectedEntity>AccountChangeEvent</selectedEntity>
14</PlatformEventChannelMember>

Use this package.xml manifest file to deploy or retrieve the channel member definition. Only API version 51.0 or later is supported for enriched fields.

1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3    <types>
4        <members>SalesEvents_AccountChangeEvent</members>
5        <name>PlatformEventChannelMember</name>
6    </types>
7    <version>63.0</version>
8</Package>

If the member is already part of the channel, you can update it with enriched fields by redeploying the PlatformEventChannelMember component with an updated definition.

Note