Yeah, that's being emailed to me. I have commented out the script I was planning on using to put the data into my data base (I named the database table headers exactly what they they were in salesforce, thus their formating). *EDIT* I was getting the error with the script commented out, as well as with it in, and with it in, I wasn't getting any data into my table. */EDIT*
PHP Code:
<?php
$hostname='xxxxx';
$username='xxxxx';
$password='xxxxx';
$dbname='xxxxx';
$con = mysql_connect($hostname,$username, $password);
mysql_select_db($dbname, $con);
/*Connect To Database
if (!$con)
{
die('Unable to connect to database! Please try again later.');
}
mysql_query("INSERT INTO basicInventory VALUES ($dwin_data['Id'], $dwin_data['Annual_Rent__c'], $dwin_data['Cap__c'], $dwin_data['City__c'], $dwin_data['Metro_Area__c'], $dwin_data['Options__c'], $dwin_data['Price__c'], $dwin_data['Remaining_Years__c'], $dwin_data['State__c'], $dwin_data['Status__c'], $dwin_data['Tenant__c'])");
*/
//Login
require_once('./salesforce_login_script.php');
error_reporting(0);
$data = fopen('php://input','rb');
$content = stream_get_contents($data);
if ($content)
{
respond('true');
}
else
{
respond('false');
}
//login script to salesforce for the $client variable ***change this path
require_once ('sfdc-client.cert');
// setup an array for the data coming in from the SOAP message
$dwin_data = array();
$dom = new DOMDocument();
$dom->loadXML($content);
$resultArray = parseNotification($dom);
unset($resultArray['sObject']);
// Data from SOAP message.
/*********************************************************
* This is where you do all your coding *
* and process the incomingin record as *
* need. use the code: *
* $temp = '<pre>' . print_r($dwin_data,true) . '</pre>'; *
* mail('youremail@address.com', 'Suject', $temp); *
* *
* To test to make sure you are getting the *
* data in an email, change the email address *
*********************************************************/
foreach ($resultArray['MapsRecords'] as $dwin_data)
{
$temp = '<pre>' . print_r($dwin_data,true) . '</pre>';
mail('myemail@gmail.com', 'Suject', $temp);
}
foreach ($resultArray['MapsRecords'] as $dwin_data)
{
$insert="INSERT INTO basicInventory ($resultArray) VALUES ('$dwin_data')";
mysql_query($insert) OR die(mysql_error());
}
//clean all the data and then exit
unset($client);
unset($dwin_data);
unset($dwin_create);
unset($records);
exit;
//functions
/* Parse a Salesforce.com Outbound Message notification SOAP packet
* into an array of notification parms and an sObject. */
function parseNotification($domDoc)
{
// Parse Notification parameters into result array
$result = array("OrganizationId" => "","ActionId" => "","SessionId" => "","EnterpriseUrl" => "","PartnerUrl" => "","sObject" => null,"MapsRecords" => array());
$result["OrganizationId"] = $domDoc->getElementsByTagName("OrganizationId")->item(0)->textContent;
$result["ActionId"] = $domDoc->getElementsByTagName("ActionId")->item(0)->textContent;
$result["SessionId"] = $domDoc->getElementsByTagName("SessionId")->item(0)->textContent;
$result["EnterpriseUrl"] = $domDoc->getElementsByTagName("EnterpriseUrl")->item(0)->textContent;
$result["PartnerUrl"] = $domDoc->getElementsByTagName("PartnerUrl")->item(0)->textContent;
// Create sObject and fill fields provided in notification
$sObjectNode = $domDoc->getElementsByTagName("sObject")->item(0);
$sObjType = $sObjectNode->getAttribute("type");
if (substr_count($sObjType,"sf:"))
{
$sObjType = substr($sObjType,3);
}
$result["sObject"] = new SObject($sObjType);
$result["sObject"]->type = $sObjType;
$sObjectNodes = $domDoc->getElementsByTagNameNS('urn:sobject.enterprise.soap.sforce.com','*');
$result["sObject"]->fieldnames = array();
$count = 0;
$tempMapRecord = array();
foreach ($sObjectNodes as $node)
{
if ($node->localName == "Id")
{
if ($count > 0)
{
$result["MapsRecords"][] = $tempMapRecord;
$tempMapRecord = array();
}
$tempMapRecord[$node->localName] = $node->textContent;
}
else
{
$tempMapRecord[$node->localName] = $node->textContent;
}
$count++;
}
// Finish last item
$result["MapsRecords"][] = $tempMapRecord;
return $result;
} // end parseNotification
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>';
}
//this is the funciton to query salesforce objects to gather data
//from different fields coming in from the SOAP message
function get_records(&$connection,&$query)
{
$queryOptions = new QueryOptions(2000);
$response = new QueryResult($connection->query($query));
// if the size is zero, where done
if ($response->size > 0)
{
$products = $response->records;
// Cycles through additional responses if the number of records
// exceeds the batch size
while (!$response->done)
{
set_time_limit(100);
$response = $connection->queryMore($response->queryLocator);
$products = array_merge($products,$response->records);
}
}
return $products;
}
?>
Thanks so much.
Bookmarks