0

I am using firebase functions to subscribe to change events for opportunity using specified cometD. my handshake all is working but the change is not received at all. i have made sure that in setup Opportunity object is selected. Any advice on what else to check or debug as why nothing is happening?

export const helloWorld = functions.https.onRequest(async(request, response) => {
    functions.logger.info("Hello logs!", {structuredData: true});
   
    const data = {
        "url": "https://XX.salesforce.com",
        "accessToken": "XXX"

    }

    await cometd_setup(data)
    functions.logger.log("cometd_setup_done")

    await cometd.handshake(function (handshake:any) {
    if (handshake.successful) {
       functions.logger.log("successful opty sending data")
       cometd.subscribe('/data/OpportunityChangeEvents', cometd_processdata)
    } else {
        logger.info('Handshake failed', handshake);
    }
})

   response.send("Hello from Firebase!");
});

the method that process data is currently simply doing a console log as below

var cometd_processdata = function (server_data:any) {
    // Do something more useful with the data
    functions.logger.info("got new data:", server_data);
};
Moblize IT
  • 1,140
  • 2
  • 18
  • 44

1 Answers1

1

The name of the subscription channel for Change Data Capture (CDC) events on standard objects is /data/<Standard_Object_Name>ChangeEvent. For an Opportunity standard object, the CDC channel is /data/OpportunityChangeEvent (no s on the end)

identigral
  • 3,920
  • 16
  • 31
  • This definitely was one issue and now i am seeing "Successful opty sending data" getting printed in the logs. As a next step i updated one of the opportunity but i do not see the cometd"_processdata being called at all. What i am missing? – Moblize IT Oct 28 '20 at 18:21
  • 1
    @Moblize IT We recommend opening a new question. The first step in troubleshooting CometD/Salesforce issues with an external client is to isolate the issue. A good approach for doing so is to implement your listener/subscription in Salesforce, first via an on-platform client with triggers, then off-platform with Salesforce-blessed client such as EMP Connector. The [Change Data Capture tutorial on Trailhead](https://trailhead.salesforce.com/en/content/learn/modules/change-data-capture) covers both of these. You'll have a better idea where to look next after that. – identigral Oct 28 '20 at 21:10