Receive an Enriched Change Event

You added a channel member to enable notifications for Account and to add enriched fields. Next, you receive a change event and verify it contains the enriched fields. 

To subscribe to the channel, we use an app from AppExchange, the Streaming Monitor app. 

Install Streaming Monitor from the AppExchange

If you’re using a Trailhead Playground org, you should have the prerequisites for the Streaming Monitor app and you can proceed with the installation steps. Otherwise, ensure that you have the requirements for the Streaming Monitor app.

Installation Steps with the Playground Starter App 

  1. In your Trailhead Playground, in the Playground Starter app page, click the Install a Package tab.
  2. For Package ID, enter 04t1t000003Po3Q, then click Install.
  3. Select Install for Admins Only, then click Install.
  4. If you see a pop-up asking you to approve third-party access, select Yes, grant access to these third-party websites and click Continue.

When your package or app is finished installing, you see a confirmation page and get an email to the address associated with your playground.

Installation Steps without the Playground Starter App 

If your org doesn't have the Playground Starter app, follow these steps to install Streaming Monitor.

  1. To connect your Playground org to AppExchange and install the app, follow the steps under the Install an AppExchange App section in Install Apps and Packages in Your Trailhead Playground in the Trailhead Playground Management module.
  2. To get your Playground username and password, see Get Your Trailhead Playground Username and Password in the Trailhead Playground Management module.
  3. For the app installation link, search for "Streaming Monitor" or use this link for the Streaming Monitor listing: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000FYEEWUA5
Note

The Streaming Monitor AppExchange app is developed by Salesforce Labs. It is used as an example tool in this project. Salesforce Labs supports this tool but not Salesforce. Streaming Monitor is also available as an open-source tool in GitHub that you can contribute to. Alternatively, you can use the empApi Lightning component in your custom Lightning app. To receive events in an external client, you can use the EMP Connector open-source, community-supported tool. For more information about EMP Connector, see the Subscribe to an Event Channel unit in the Change Data Capture Basics Trailhead module. 

Subscribe to the Channel and Receive an Initial Change Event

Use Streaming Monitor to subscribe and receive an initial change event after creating a new account record. Let's get an initial event message to try things out. 

Subscribe to the Custom Channel

After you’ve installed Streaming Monitor, launch it to subscribe to the custom channel.

  1. Click App Launcher, and enter Streaming Monitor in the search box. Select Streaming Monitor.
  2. In the Streaming Monitor app, under Actions, click Subscribe to a channel.
  3. Under Event type, select Change Data Capture channel.
  4. For the channel, append SalesEvents__chn. The full channel name is /data/SalesEvents__chn.
  5. Click Subscribe.
  6. You get a popup that confirms the successful subscription. Dismiss it.

Launch the Streaming Monitor app

Note

If you receive a "A Component Error has occurred" error message, clear your browser cache. If needed, sign into your Trailhead Playground again.

Create an Account Record

  1. Click App Launcher, and enter Accounts in the search box.
  2. Right-click Accounts and select to open the link in a new tab.
  3. In the new tab, search for Accounts in App Launcher.
  4. Create an account with these values.
    1. Account Name: Astro
    2. Industry: Apparel
    3. External Account ID: 123
    4. Phone: 4155551212
  5. Switch to the Streaming Monitor tab. A new event appears in the timeline view as a dot.
  6. An event appears in the timeline view of Streaming Monitor
  7. To view the event message, click the dot, which represents the received event. The event payload looks similar to this example.
{
  "LastModifiedDate": "2021-02-04T16:31:50Z",
  "External_Account_ID__c": "123",
  "Name": "Astro",
  "Industry": "Apparel",
  "Phone": "4155551212",
  "OwnerId": "005B0000006GudtIAC",
  "CreatedById": "005B0000006GudtIAC",
  "CleanStatus": "Pending",
  "ChangeEventHeader": {
    "commitNumber": 10714379525658,
    "commitUser": "005B0000006GudtIAC",
    "sequenceNumber": 1,
    "entityName": "Account",
    "changeType": "CREATE",
    "changedFields": [],
    "changeOrigin": "com/salesforce/api/soap/51.0;client=SfdcInternalAPI/",
    "transactionKey": "00006bed-29af-3dd6-128a-a534cde0836f",
    "commitTimestamp": 1612456310000,
    "recordIds": [
      "001B000001LwtBEIAZ"
      ]
    },
  "CreatedDate": "2021-02-04T16:31:50Z",
  "LastModifiedById": "005B0000006GudtIAC"
}
Note

Streaming Monitor shows only the payload part of the event message. The event replay ID and schema are omitted for brevity. 

This event isn’t enriched yet with extra fields because it is for a create operation. Enrichment is available for update and delete operations. However, it does contain the External_Account_ID__c and Industry fields. Why? The fields are present because they’re added as part of the new populated fields, and not as enriched fields. 

Receive an Enriched Change Event

Let’s validate that enriched fields are indeed added to change events. While still subscribed to the SalesEvents__chn channel, you update the same record and wait for a change event. 

  1. Switch to the tab for the account you created earlier.
  2. Edit the Type field and select Customer - Direct.
  3. Save the record.
  4. Switch to Streaming Monitor. To view the new event payload, click the dot representing the event that comes after the previous event in the timeline.
{
  "LastModifiedDate": "2021-02-04T16:33:52Z",
  "External_Account_ID__c": "123",
  "Industry": "Apparel",
  "Type": "Customer - Direct",
  "ChangeEventHeader": {
    "commitNumber": 10714380023591,
    "commitUser": "005B0000006GudtIAC",
    "sequenceNumber": 1,
    "entityName": "Account",
    "changeType": "UPDATE",
    "changedFields": [
    "Type",
    "LastModifiedDate"
    ],
    "changeOrigin": "com/salesforce/api/soap/51.0;client=SfdcInternalAPI/",
    "transactionKey": "00006c09-7462-0b8f-6b93-81f536850f61",
    "commitTimestamp": 1612456432000,
    "recordIds": [
      "001B000001LwtBEIAZ"
    ]
  }
}

Even though only the Type field was updated, the event payload also includes the enriched fields, External_Account_ID__c and Industry, as shown in this example event. The changedFields field shows what fields changed. In this case, it contains the Type field. In addition, this update caused the LastModifiedDate field to change, so it is listed also as a changed field. 

Resources

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