As part of a second-generation managed package, need to enable Change Data Capture (CDC) for the Opportunity object.

Can this be done via Apex in a PostInstall for the managed package? Been Googling for examples but could not find any.

1 Answer 1


No, it cannot.

Enabling Change Data Capture for an object is done via the Metadata or Tooling APIs against the PlatformEventChannelMember entity.

Your postinstall scripts are subject to a variety of limitations, including that

It can’t access Session IDs.

You would need an API-enabled Session Id (for a System Administrator) to make a call to mutate PlatformEventChannelMember.

This is something you'll generally have to handle through admin-oriented documentation unless you're delivering your package via a tool like (my team's) MetaDeploy, which can automate API-based setup steps after package installation.

You could also in theory handle it through an an-app setup UI that calls the Metadata API, but you'll have to do so carefully as Security Review standards for consuming session ids like that have changed recently, and I'm not myself fully up to speed on what's allowed.

  • First - thank you for the response! Second - bummer this can't be handled in the PostInstall. As we install a Connected App, perhaps we could have a callout that triggers something on our server to do the final configuration via REST API? Commented Feb 10, 2023 at 21:07
  • How would you be authorized into the org at that point, though?
    – David Reed
    Commented Feb 10, 2023 at 21:58
  • More broadly: my position is always that you shouldn't take a system-level action without telling the system admin what you're doing and giving them a chance to refuse first.
    – David Reed
    Commented Feb 10, 2023 at 21:58
  • Is it feasible to create an LWC component for Post Installation that would describe each step and give the System Admin a button to perform these tasks? Or do you think it would be a problem in the security review? Commented Feb 10, 2023 at 22:07
  • The first post-installation step is for the System Administrator to (manually) configure the Connected App. This permits us to run our daily synchronization process. Commented Feb 10, 2023 at 22:09

You must log in to answer this question.

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