Salesforce Outbound Message Relay

In this post I’m gonna talk about how to relay the Salesforce outbound message to another environment. While trying to integrate Salesforce with another system, we usually use web service as method to communicate between the two. now the problem is that the outbound message can only send the message to publicly available servers.

This is not a good scenario because the publicly accessible servers is usually the production server, and doing development in production server is generally bad idea. A better approach would be if we have a message relayer that sits on the public server and then it forward any message to targeted environments, like for example the developer machine or our staging server.

Setting up the relayer

Before we go on, you should have some knowledge on the Salesforce Outbound Message itself, if not you really should read about it here.

Done reading that ?. cool, let’s move on

Below we got a simple example of Outbound Message Listener

class MyNotificationListener : INotificationBinding
{
public notificationsResponse notifications(notifications n)
{
notificationsResponse r = new notificationsResponse();
r.Ack = true;
return r;
}
}

 

It’s not really doing much at the moment, so let’s changed that

class MyNotificationListener : INotificationBinding
{
public notificationsResponse notifications(notifications notifications)
{
var notificationsResponse = new notificationsResponse();
notificationsResponse.Ack = true;

//set the target end point to be our dev machine
var serviceClient = new NotificationBindingClient(“account-dev”);


 


 
//the AccountServiceReference.notifications refers to the class generated from WSDL
var request = new AccountServiceReference.notifications
{
ActionId = notifications.ActionId,
EnterpriseUrl = notifications.EnterpriseUrl,
Notification = notifications.ToArray(),
OrganizationId = notifications.OrganizationId,
PartnerUrl = notifications.PartnerUrl,
SessionId = notifications.SessionId
};

serviceClient.notifications(request);
serviceClient.Close();

return notificationsResponse;
}
}

You might wonder where “account-dev” is coming from, it’s actually the endpoint name that i setup on my web.config that points to one of the dev machine. So it basically boils down to this steps

  1. Pass the endpoint to the generated NotificationBindingClient
  2. Copy the value that we want to pass in
  3. Return the response so the Salesforce outbound message doesn’t get timeout or bad response
    Of course this post doesn’t talk about handling duplicate message in the outbound messages, and or how to build a queuing system to handle the outbound messages when under heavy load. There’s a good post already that you can find here
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s