function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
john hopejohn hope 

salesforce Outbound message Listener

Hello there,

 

Im having trouble on how to create a listener of salesforce outbound message. Do you have a step-by-step lesson on how to create a salesforce outbound listener ? specially in java and php language ? Please help me.

 

Kind Regards,

 

John

colingcoling

Hi John,

 

Are you looking for an example script that you can use? Below is an example of a php Outbound message listener that has been in use for a long time. You should be able to expand on it.

 

<?php
header("Content-Type: text/xml\r\n");
ob_start();

 

// Sends SOAP response to SFDC
function respond($tf) {
         print '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <soapenv:Body>
         <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
         <Ack>' . $tf . '</Ack>
         </notifications>
         </soapenv:Body>
         </soapenv:Envelope>';
}

 

// Get raw post data
$data = fopen('php://input', 'rb');
$content = fread($data,5000);

 

//Now do what ever you will with the message in $content - you should parse it (xml) etc.

...

 

ob_end_clean();

respond('true');

?>

 

Simply set the url in the outbound message form on Salesforce to point to your script.

 

CG

 

john hopejohn hope

Thanks CG, actually im new in salesforce. and truely speaking i dont know what to do i hope you understand. This is the scenario of my problem "i want to send a message to my local machine, when there is a new record that is added in the  custom objects that ive made and i want to make a code or a listener that will receive this message, so that i can see the data update it and sent it back to salesforce ".In your given code how do i know that i get the right thing or how do i know that the listener is successful can you please help me ? Hope you understand

colingcoling

John,

 

- The code snippet I gave you should allow you to receive the outbound message in variable $contents. At the very least, you can add code that, for example (for initial testing purposes) will email you the message received in $contents.

 

Taking one step at a time:

 

- My approach would be a test-driven one.

ie.

 - Add some code that will show the message received from Salesforce (eg. mail $contents to you)

 - Create the Salesforce workflow and outbound message action, giving the url of your listener script

 - Switch on debugging in Salesforce so you know what it thinks it did

 - Save a record - which will cause the workflow rule to fire

 - Check from the Salesforce debug log that the workflow rule did in fact fire

 - From your listener output, inspect the contents sent by Salesforce

 - Add/change your code to process this output - eg. it should be in xml format. You will need to parse the xml.

 - Repeat and refine until you get meaningful results

 

 As you are new to Salesforce, your progress will most likely be slow at the beginning - Salesforce is not easy if you are not familiar with it. You may want to practice firing workflow rules that send emails instead of outbound messages until you can be confident that the rule is firing when you want it to. Then switch over to sending outbound messages and deal with receiving the message on your server.

 

CG

 



mearmear

Hi There,

 

I'm trying to build an outbound message listener in c# .net. I have followed the example and instructions in the "Building a Listener" article - after the outbound message was configured in Salesforce, I downloaded the wsdl file and generated the interface file (ie. NotificationServiceInterface.cs). I added the file to my project, compiled it, and created an asmx file that implements the interface.

 

When Salesforce tries to hit this endpoint, I see the following message under Monitoring/Outbound Messages: "(404)Not Found" under  Delivery Failure Reason. I have verified that it is publicly available and have tested the service using a tool called .NET WebService Studio.

 

Am I missing anything else to get this to work correctly?

 

Thanks in advance,

Mary

AmigoAmigo

Dear John,

 

I write two post which you might think useful to handle Salesforce Outbound Message.

 

Capture Salesforce Outbound Message with a PHP SOAP Listener

 

collins's reply is very useful. There are still work after received. It's not so straight forward to use SimpleXML to parse the message with namespace. You need more information about SimpleXMLElement::children

 

Parse XML with namespace by SimpleXML in PHP

 

Wish it helps!

 

Best regards,

 

Amigo

 

 

 

 

jason_lowryjason_lowry

After a lot of searching and trial/error, I found this:

 

https://gist.github.com/tanakahisateru/7524348

 

I believe this is the _correct_ way of doing it. A lot of others posted some really good ideas, but I don't think manually parsing the XML is the right way to go when PHP provides SOAP classes and Salesforce provides a WSDL 

MartinHaagenMartinHaagen

I agree with you Jason that you should build a SoapServer that listens to the request from Salesforce. Please have a look at this post 

 

http://webaholic.se/development/salesforce/dreamforce-presentation/

 

where you will find my slides and demo code from a Dreamforce session I had the year. There are listner examples for both .NET and PHP in there. 

 

I used wsdl2php to build the data structes needed for the SoapServer when I build the demos. 

AmigoAmigo

Dear Jason,

 

The git hub page in your post is created by Hisateru Tanaka. He is a famous PHP programmer in Kansai, Japan. I have pass your message to him via Facebook. You may found him at:

 

https://www.facebook.com/tanakahisateru/about

 

It is very nterested story about this Outbound Message Listener.

 

On 2013/11/14, Tanaka San (San is similiar to Mr. in Japanese culture) ask me if I know how to handle message from Salesforce. I spend two days (2013/11/16) to write a small PHP program to parse and read the field value successfully. Then I also create two post and share.

 

But Tanaka San provides a better solution on 2013/11/18 and share via GitHub, he study on his own without reading my code. That's why our code are so different.

 

There is no doubt that his code is better for reuse and easier to maintain. I agreed with you this is the best solution I have found on the web.

 

My upcomming two post in the second and thrid week in December will have a detail explain about the parser and Tanaka San's code to help more salesforce developers.

 

Again, thank you for your comments. I really like to see positive feedback from other Salesforce developers! :)

Have a nice day!

 

Best regards,

 

Amigo

NadulaNadula
Hi Coling, thanks for the post. My listener script was keep calling multiple times, didn't know listener script should send a respond.

And had hard time reading the incoming values to php. Following is how I do it succesfully. Hope this helps someone.

ob_start(); 
$capturedData = fopen('php://input', 'rb');
$content = fread($capturedData,5000);
ob_end_clean();
$rcXML = simplexml_load_string($content);

$recordID = trim($rcXML->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://soap.sforce.com/2005/09/outbound')->notifications->Notification->sObject->children('urn:sobject.enterprise.soap.sforce.com')->RecordID__c.PHP_EOL);

Note: RecordID__c is the incoming variable


Cheers
Nadula