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. If you aren’t using a Trailhead Playground org, make sure that Lightning Experience is enabled in your org. For more information, see Verify that Lightning Experience is Turned On in Salesforce Help.
Installation Steps
In your Trailhead Playground, if you see a tab in your org labeled Install a Package, great! Follow these steps:
- Click the Install a Package tab.
- Paste
04t1t000003Lgqi
into the field.
- Click Install.
- Select Install for Admins Only, then click Install.
If you don't see the Install a Package tab, open the App Launcher (), find Playground Starter, and follow the steps.
If you don’t see the Playground Starter app, copy this package installation link and check out Install a Package or App to Complete a Trailhead Challenge on Salesforce Help.
When the package is finished installing, you see a confirmation page and get an email to the address associated with your playground.
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.
- Click App Launcher, and enter
Streaming Monitor
in the search box. Select Streaming Monitor.
- In the Streaming Monitor app, under Actions, click Subscribe to a channel.
- Under Event type, select Custom Channel - Change event.
- For the channel, append
SalesEvents__chn
. The full channel name is/data/SalesEvents__chn
.
- Click Subscribe.
- You get a popup that confirms the successful subscription. Dismiss it.
Create an Account Record
- Click App Launcher, and enter
Accounts
in the search box.
- Right-click Accounts and select to open the link in a new tab.
- In the new tab, search for
Accounts
in App Launcher.
- Create an account with these values.
- Account Name:
Astro
- Industry: Apparel
- External Account ID:
123
- Phone:
4155551212
- Switch to the Streaming Monitor tab. A new event appears in the timeline view as a dot.
- To view the event message, click the dot, which represents the received event. The event payload looks similar to this example.
{ "LastModifiedDate": "2023-08-29T19:22:19Z", "External_Account_ID__c": "123", "Name": "Astro", "Industry": "Apparel", "Phone": "4155551212", "OwnerId": "0058b00000HpWcRAAV", "CreatedById": "0058b00000HpWcRAAV", "CleanStatus": "Pending", "ChangeEventHeader": { "commitNumber": 11658980597990, "commitUser": "0058b00000HpWcRAAV", "sequenceNumber": 1, "entityName": "Account", "changeType": "CREATE", "changedFields": [], "changeOrigin": "com/salesforce/api/soap/58.0;client=SfdcInternalAPI/", "transactionKey": "00006bed-29af-3dd6-128a-a534cde0836f", "commitTimestamp": 1693336939000, "recordIds": [ "0018b00002Vlq7xAAB" ] }, "CreatedDate": "2023-08-29T19:22:19Z", "LastModifiedById": "0058b00000HpWcRAAV" }
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.
- Switch to the tab for the account you created earlier.
- Edit the Type field and select Customer - Direct.
- Save the record.
- 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": "2023-08-29T19:26:11Z", "External_Account_ID__c": "123", "Industry": "Apparel", "Type": "Customer - Direct", "ChangeEventHeader": { "commitNumber": 11658983493935, "commitUser": "0058b00000HpWcRAAV", "sequenceNumber": 1, "entityName": "Account", "changeType": "UPDATE", "changedFields": [ "Type", "LastModifiedDate" ], "changeOrigin": "com/salesforce/api/soap/58.0;client=SfdcInternalAPI/", "transactionKey": "000156e3-6f79-5781-b351-6085bc252aaf", "commitTimestamp": 1693337171000, "recordIds": [ "0018b00002Vlq7xAAB" ] } }
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