Update an Existing Channel Member
If a channel member already exists, you can’t perform a POST request to overwrite it with enriched fields. Instead, update the channel member by doing a PATCH request. In this step, you'll replace the enriched fields on the SalesEvents channel with one enriched field: the Phone
field.
Query the Channel ID
- In your fork of the Salesforce Platform APIs collection, expand Event Platform > Custom Channels, and then click List event channels.
- In the Params tab, for the q key value, append the following WHERE clause:
WHERE DeveloperName='SalesEvents'
. The full URI is:{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=SELECT Id,DeveloperName,MasterLabel,ChannelType FROM PlatformEventChannel WHERE DeveloperName='SalesEvents'
- Click Send.
- The returned response includes the channel ID in the
Id
field and looks similar to the following example. Copy theId
value to use it in the next step.
Query the Channel Member ID
- In your forked collection, under Event Platform > Custom Channels, click List channel members.
- In the Params tab, for the q key value, append the following WHERE clause and replace
<channel ID from query>
with the Id you obtained from the previous step:WHERE EventChannel='<channel ID from query>' AND SelectedEntity='AccountChangeEvent'
. The full URI looks as follows:{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=SELECT Id,DeveloperName,EventChannel,FilterExpression,SelectedEntity FROM PlatformEventChannelMember WHERE EventChannel='<channel ID from query>' AND SelectedEntity='AccountChangeEvent'
- Click Send.
- The returned response includes the channel member Id in the
Id
field (for example,0YL8b000000sXvSGAU
) and looks similar to this example. Copy thisId
value to use it in the next step.
Make a PATCH Request on PlatformEventChannelMember
- In your forked collection, under Event Platform > Custom Channels > Change Data Capture, and click Add enriched fields to channel member.
- In the Params tab, add the channel member
Id
value you copied for thePLATFORM_EVENT_CHANNEL_MEMBER_ID
parameter. - Click Body and ensure that raw and JSON options are selected.
- Replace the body with this JSON body.
- Click Send.
- Verify that the response status is 204 No Content.
Subscribe to the Channel and Receive the New Enriched Field
Validate that the enrichment update was done correctly by subscribing to the custom channel, updating a record, and verifying the enriched fields array in the received change event. While still subscribed to the SalesEvents__chn
channel, let’s update the account again.
- In your Trailhead Playground, switch to the tab for the account you created earlier.
- Edit the
Type
field and change it to Other. - Save the record.
- Switch to the Streaming Monitor tab. Click the newest dot in the timeline to view the received event.
- The event payload includes the
Phone
field as an enriched field. It doesn't containExternal_Account_ID__c
orIndustry
because they're no longer enriched fields. ThechangedFields
array in the received event message shows what fields changed.
In this project, you learned many things: how to create a channel, add members to enable notifications for objects, configure event enrichment, and subscribe to a channel to receive events. You used various tools to perform these steps: Postman and the Streaming Monitor app. Now you’re well-equipped to tackle Change Data Capture channels and event enrichment!