1

I would like to retrieve things like CreatedBy.Name on Salesforce Change Data Capture. How may I accomplish it?

I have looked into Enrich Change Events with Extra Fields, which mentions that Lookups are supported.

I can enrich with direct fields (e.g. CreatedById or other text fields) by creating a custom channel via platformEventChannels + platformEventChannelMembers. See below an example of platformEventChannelMembers:

<?xml version="1.0" encoding="UTF-8" ?>
<PlatformEventChannelMember xmlns="http://soap.sforce.com/2006/04/metadata">
    <enrichedFields>
        <name>CreatedById</name>
    </enrichedFields>
    <eventChannel>Channelname__chn</eventChannel>
    <selectedEntity>Object__ChangeEvent</selectedEntity>
</PlatformEventChannelMember>

1 Answer 1

2

Lookup fields are supported, but following the relationship to a related field is not.

The same document you reference says this:

For a relationship field, you can select only the field as an enriched field. You can’t traverse the fields on the related object. The enriched change event contains the ID of the related record. For example, to enrich a contact change event with the ID of the related account, select the Account relationship field as the name of the enriched field for ContactChangeEvent, and not Account.Name. For custom relationship fields, specify the relationship field name with the __c suffix, such as RelField__c.

You could of course create a field that contained this data populated via a flow or a trigger and have it send that. It could potentially get difficult to manage because it would reflect null on create and the old value on a change of ownerId.

I investigated enriched fields myself and found similar limitations - I ended up not using enriched fields, but defining my own CDC trigger handler, adding my own "enriched" fields and dispatching a custom platform event.

3
  • 1
    Thanks a lot, Caspar, that enlights me; I have overlooked that aspect. CDC is an excellent no-code tool, but indeed some limitations are still annoying. Commented Jun 27, 2023 at 8:36
  • 1
    Sorry to be the bringer of bad news, but sometimes that's how the cookie crumbles eh. Commented Jun 27, 2023 at 20:53
  • Nah, you are all good Casper; it is better to know the limitations than not. Commented Jun 28, 2023 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .