Skip to main content

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

  1. In Postman, under Tooling, select GET Tooling Query.
  2. 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'
  3. Click Send.
  4. The returned response includes the channel ID in the Id field and looks similar to the following example. Copy the Id 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

  1. In Postman, under Tooling, click GET Tooling Query.
  2. 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'
  3. Click Send.
  4. The returned response includes the channel member Id in the Id field (for example, 0v8B0000000L0BXIA0) and looks similar to this example. Copy this Id 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

  1. 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:
    1. Under Tooling, click POST Post Tooling sObject.
    2. In the new tab that opens for this request, replace the :SOBJECT_API_NAME placeholder in the URI with PlatformEventChannelMember. The resulting URI is: {{_endpoint}}/services/data/v{{version}}/tooling/sobjects/PlatformEventChannelMember
  2. 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
  3. Change POST to PATCH.
  4. Click Body and ensure that raw and JSON options are selected.
  5. Replace the body with this JSON body.
    {
      "FullName": "SalesEvents_chn_AccountChangeEvent",
      "Metadata": {
      "enrichedFields": [
        {
          "name": "Phone"
        }
      ],
      "eventChannel": "SalesEvents__chn",
      "selectedEntity": "AccountChangeEvent"
      }
    }
  6. Click Send.
  7. Verify that the response status is 204 No Content.
Note

The update process outlined the steps to do any update to enriched fields, which applies to adding, deleting, or replacing fields. If you're only deleting an enriched field, a simple way to do this is by performing a DELETE request on EnrichedField in Tooling API. First, get the Id of the enriched field to delete by performing a query like the one you did in the "Add a Channel Member and Configure Change Event Enrichment" step. Then, perform a DELETE request on /tooling/sobjects/EnrichedField/<Id>. You can use EnrichedField to delete a field but not to update it.

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.

  1. In your Trailhead Playground, switch to the tab for the account you created earlier.
  2. Edit the Type field and change it to Other.
  3. Save the record.
  4. Switch to Streaming Monitor. Click the newest dot in the timeline to view the received event.
  5. The event payload includes the Phone field as an enriched field. It doesn't contain External_Account_ID__c or Industry 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! 

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities