2

I have a public API endpoint that is successfully receiving an outbound message from salesforce (triggered by a workflow action).

Usually when I create an API for webhooks (webhooks are the same concept as outbound messages) I will have one single API route like:

Router.route('/api/webhooks/:provider'({ provider }, request, response) => {
     //do stuff here with request
});

then I will hit that route with different services as the parameter. So my outbound messages are being sent to:

'https://www.mywebsite.com/api/webhooks/salesforce'

and if I were to direct webhooks from stripe I'd do:

'https://www.mywebsite.com/api/webhooks/stripe'

Then in my node app I can see if the parameter is salesforce or something else (like stripe) and I can act accordingly.

This is working all good and I am getting request from salesforce and can console.log this xml response. But I am unsure how to figure out which outbound message/workflow action was triggered (I have several). For instance I have to do different things if the OM is for "account created" vs "account updated".

I gave the OM and workflow action a name called like "ACCOUNT_CREATED" which I could really use in my node app, but it doesn't seem to be sent from salesforce? I see an actionId but how exactly can I use that to figure out which action is triggered? That actionId is unique per action fired not unique per workflow actions I have created from the CMS-- correct?

normally with stripe recurring subscription api I would get the OM (which stripe calls a webhook) from stripe, then there is a property I can check it is for, like "charge.succeeded" or "charge.failed" or "invoice.issued" and so I can have one single api input like above, and can distinguish the next step from checking that property to see what the vent was (charge succeeded, etc).

It seems like the only way to do this with salesforce is to just have different URLs for each thing I want to do, which isn't the end of the world but the other way is much cleaner especially as you have other webhooks from other third-party services...

I feel like there must be some way to distinguish what action I am receiving from the xml-- please help!

Let me know if I can provide more information/context

4
  • 1
    You might consider distinct endpoints to help you distinguish between operations.
    – Adrian Larson
    Commented Feb 2, 2017 at 22:00
  • Thanks for fast response, Adrian. I was going to go that direction but wanted to double check there wasn't another way. It would be much cleaner (for me) to have a way to distinguish from the payload.
    – arcom
    Commented Feb 2, 2017 at 22:02
  • You can distinguish insert vs update by whether or not the Id is null, but not much more than that from the XML, I think.
    – Adrian Larson
    Commented Feb 2, 2017 at 22:03
  • Related: Outbound Messaging: ActionId Commented Feb 2, 2017 at 22:39

1 Answer 1

3

The XML will look something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<notifications xmlns="http://soap.sforce.com/2005/09/outbound" xmlns:ns2="urn:sobject.enterprise.soap.sforce.com">
    <OrganizationId>00DK00000000001AAA</OrganizationId>
    <ActionId>04k70000000L1TLAA0</ActionId>
    <SessionId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    <EnterpriseUrl>https://csX.salesforce.com/services/Soap/c/35.0/00DK00000000001AAA</EnterpriseUrl>
    <PartnerUrl>https://csX.salesforce.com/services/Soap/u/35.0/00DK00000000001AAA</PartnerUrl>
    <Notification>
        <Id>04lK000000PJu8TIAT</Id>
        <sObject>
            <ns2:Id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
        </sObject>
    </Notification>
    <!-- ... -->
</notifications>

Here the ActionId has the key prefix 04k, which is WorkflowOutboundMessage.

These WorkflowOutboundMessage records are exposed via the Tooling API. So you can do a SOQL query against them.

Select Id,Name,IntegrationUserId,ManageableState,NamespacePrefix,ApiVersion,EntityDefinitionId from WorkflowOutboundMessage

enter image description here

Or, since we know the ID:

Select Id,Name,IntegrationUserId,ManageableState,NamespacePrefix,ApiVersion,EntityDefinitionId,FullName,Metadata from WorkflowOutboundMessage where ID = '04k70000000L1TLAA0'

From the FullName I know my Workflow outbound message is from "Account.DFB__AccountOutboundMessage". There are probably other useful details hidden in the Metadata field.

You must log in to answer this question.

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