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 Postman, under Tooling, select GET Tooling Query.
- In the Params tab, replace the value in the row for q with:
SELECT Id FROM PlatformEventChannel WHERE DeveloperName='SalesEvents'
. The full URI looks as follows:{{_endpoint}}/services/data/v{{version}}/tooling/query/?q=SELECT Id 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/v51.0/tooling/sobjects/PlatformEventChannel/0YLB00000008OIFOA2" }, "Id": "0YLB00000008OIFOA2" } ] }
Query the Channel Member ID
- In Postman, under Tooling, click GET Tooling Query.
- In the Params tab, replace the value in the row for q with the following value and replace
<channel ID from query>
with the Id you obtained from the previous step:SELECT Id,DeveloperName,EventChannel,SelectedEntity FROM PlatformEventChannelMember 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,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,0v8B0000000L0BXIA0
) 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/v51.0/tooling/sobjects/PlatformEventChannelMember/0v8B0000000TNa7IAG" }, "Id": "0v8B0000000TNa7IAG", "DeveloperName": "SalesEvents_chn_AccountChangeEvent", "EventChannel": "0YLB00000008OIFOA2", "SelectedEntity": "AccountChangeEvent" } ] }
Make a PATCH Request on PlatformEventChannelMember
- If you performed a POST request previously in Postman, stay on the same request page and ensure that the URI ends with
/PlatformEventChannelMember
. Otherwise, perform these steps:- Under Tooling, click POST Post Tooling sObject.
- In the new tab that opens for this request, replace the
:SOBJECT_API_NAME
placeholder in the URI withPlatformEventChannelMember
. The resulting URI is:{{_endpoint}}/services/data/v{{version}}/tooling/sobjects/PlatformEventChannelMember
- Append a forward slash (
/
) followed by the channel member Id you copied in the previous step to the end of the URI. The resulting URI is similar to this example except for the Id value that could be different in your case:{{_endpoint}}/services/data/v{{version}}/tooling/sobjects/PlatformEventChannelMember/0v8B0000000PBNFIA4
- Change POST to PATCH.
- 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 Streaming Monitor. 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. The changedFields array in the received event message shows what fields changed.
{ "LastModifiedDate": "2021-02-04T16:40:26Z", "Phone": "4155551212", "Type": "Other", "ChangeEventHeader": { "commitNumber": 10714381598794, "commitUser": "005B0000006GudtIAC", "sequenceNumber": 1, "entityName": "Account", "changeType": "UPDATE", "changedFields": [ "Type", "LastModifiedDate" ], "changeOrigin": "com/salesforce/api/soap/51.0;client=SfdcInternalAPI/", "transactionKey": "00006c65-60c8-05bb-6511-032044bd19c9", "commitTimestamp": 1612456826000, "recordIds": [ "001B000001LwtBEIAZ" ] } }
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!