Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Last active November 25, 2016 10:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanakahisateru/7524348 to your computer and use it in GitHub Desktop.
Save tanakahisateru/7524348 to your computer and use it in GitHub Desktop.
<?php
/**
* Salesforce Workflow Outboud message reciever sample in PHP
*
* requires: php-soap extension
*
* At 1st you should download WSDL of the message and put it besides this script.
*/
$wsdl = __DIR__ . '/' . 'wfoutbound.xml';
ini_set("soap.wsdl_cache_enabled", "0"); // clean WSDL for develop
function log_writeln($log)
{
file_put_contents(__DIR__ . '/log/' . @date('Y-m-d') . '.log', $log . "\n", FILE_APPEND);
}
/**
* Salesforce Outbound Response type
*/
class Response
{
public $Ack;
function __construct($success)
{
$this->Ack = $success;
}
public static function success()
{
return new static(true);
}
public static function fail()
{
return new static(false);
}
}
/**
* Bound request handler
*/
function notifications($args=null)
{
log_writeln(date('Y-m-d H:i:s'));
log_writeln(print_r($args, true));
/*
You can get object via $args like below:
stdClass Object
(
[EnterpriseUrl] => https://ap.salesforce.com/services/Soap/c/29.0/00XXXXXXXXXXXX
[PartnerUrl] => https://ap.salesforce.com/services/Soap/u/29.0/00XXXXXXXXXXXX
[Notification] => stdClass Object
(
[Id] => 0XXXXXXXXXXXXXXXX (Notification ID)
[sObject] => stdClass Object
(
[Id] => 0XXXXXXXXXXXXXXX (Object ID)
... (Fields that you selected)
)
)
)
Your object would be in: $args->Notification->sObject;
*/
// Success response
return Response::success();
}
$server = new SOAPServer($wsdl); // Never link to Salesforce's WSDL URL
$server->addFunction('notifications');
$req = file_get_contents('php://input');
// log_writeln($req);
ob_start();
$server->handle($req);
$resp = ob_get_clean();
// log_writeln($resp);
echo $resp;
@dbernar1
Copy link

I saw some messages sent with multiple Notification sections, so something like:

 /*
    stdClass Object
    (
        [EnterpriseUrl] => https://ap.salesforce.com/services/Soap/c/29.0/00XXXXXXXXXXXX
        [PartnerUrl] => https://ap.salesforce.com/services/Soap/u/29.0/00XXXXXXXXXXXX
        [Notification] => Array
        (
            [0] => stdClass Object
            (
            [Id] => 0XXXXXXXXXXXXXXXX (Notification ID)
            [sObject] => stdClass Object
                (
                    [Id] => 0XXXXXXXXXXXXXXX (Object ID)
                    ... (Fields that you selected)
                )
            )
        )
    )

    Your object would be in: $args->Notification->sObject;
    */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment