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.
{ "size": 1, "totalSize": 1, "done": true, "queryLocator": null, "entityTypeName": "PlatformEventChannel", "records": [ { "attributes": { "type": "PlatformEventChannel", "url": "/services/data/v58.0/tooling/sobjects/PlatformEventChannel/0YL8b000000sXvSGAU" }, "Id": "0YL8b000000sXvSGAU", "DeveloperName": "SalesEvents", "MasterLabel": "Custom Channel for Sales App", "ChannelType": "data" } ] }
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.
{ "size": 1, "totalSize": 1, "done": true, "queryLocator": null, "entityTypeName": "PlatformEventChannelMember", "records": [ { "attributes": { "type": "PlatformEventChannelMember", "url": "/services/data/v58.0/tooling/sobjects/PlatformEventChannelMember/0v88b0000004CgVAAU" }, "Id": "0v88b0000004CgVAAU", "DeveloperName": "SalesEvents_chn_AccountChangeEvent", "EventChannel": "0YL8b000000sXvSGAU", "FilterExpression": null, "SelectedEntity": "AccountChangeEvent" } ] }
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.
{ "FullName": "SalesEvents_chn_AccountChangeEvent", "Metadata": { "enrichedFields": [ { "name": "Phone" } ], "eventChannel": "SalesEvents__chn", "selectedEntity": "AccountChangeEvent" } }
- 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.
{ "LastModifiedDate": "2023-08-29T19:37:19Z", "Phone": "4155551212", "Type": "Other", "ChangeEventHeader": { "commitNumber": 11658991958431, "commitUser": "0058b00000HpWcRAAV", "sequenceNumber": 1, "entityName": "Account", "changeType": "UPDATE", "changedFields": [ "Type", "LastModifiedDate" ], "changeOrigin": "com/salesforce/api/soap/58.0;client=SfdcInternalAPI/", "transactionKey": "0001577e-f890-0389-9d0d-c918449ad498", "commitTimestamp": 1693337839000, "recordIds": [ "0018b00002Vlq7xAAB" ] } }
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!