How to subscribe to Salesforce connected app webhooks?

Viewed 187

I want to implement a connected OAuth app in Salesforce which should trigger push events in case some entities changed, for example an opportunity was closed.

Zapier implemented something similar https://zapier.com/apps/salesforce/integrations/webhook

Could not find something I need which is a simple way to subscribe to entity changes using the OAuth client's token and passing a webhook endpoint. I read about apex callouts, streaming API and outbound messages.

2 Answers

Yeah, we solved this exact problem at Fusebit and I can help you understand the process as well.

Typically speaking here's what you need to do:

  1. Create triggers on the Salesforce Objects you want to get updates for
  2. Upload Apex class that will send an outgoing message to a pre-determined URL
  3. Enable Remote Site Setting for the Domain you want to send the message to
  4. Add in Secret Verification (or other auth method) to prevent spamming of your external URL

If you're leveraging javascript, then you can use the jsforce sdk & salesforce tooling API to push the code into the salesforce instance AFTER the Auth flow has occurred AND on Salesforce Instances that have API access enabled (typically - this is enterprise and above OR professional with API enabled).

This will be helpful for you to look through: https://jamesward.com/2014/06/30/create-webhooks-on-salesforce-com/

FYI - Zapier's webhooks implementation is actually polling every 15 minutes, instead of real-time incoming events.

In which programming language?

For consuming outbound messages you just need to be able to accept an XML message and send back "Ack" message to acknowledge receiving, otherwise SF will keep trying to resend it for 24h.

For consuming platform events / streaming API / Change Data Capture (CDC) you'll need to raise the event in SF (Platform Event you could raise from code, flow, process builder, CDC would happen automatically, you just tell it which objects it should track).

And then in client app you'd need to login to SF (SOAP or REST API), subscribe to channel (any library that supports cometd should be fine). Have you seen "EMP Connector", mentioned for example in https://trailhead.salesforce.com/en/content/learn/modules/change-data-capture/subscribe-to-events?trail_id=architect-solutions-with-the-right-api ?

Picking right messaging way is an art, there's free course that can help: https://trailhead.salesforce.com/en/content/learn/trails/architect-solutions-with-the-right-api And pretty awesome PDF if you want to study for certification: https://resources.docs.salesforce.com/sfdc/pdf/integration_patterns_and_practices.pdf

Related