All, I piggy-backed off of Mike's original SF to Oracle scripts to create a query call to Salesforce and feed the query result into a Google table Visualization. For this exercise, I'm querying the Opportunity object for all opportunity ID's with a stage name of "LOI/Going to Contract".
FYI: I'm running PHP toolkit version 13.1 and PHP version 5.3. It only works in Firefox, Chrome, and IE7. There are known compatibility issues between IE8 and the google visualization API. I had to tweak the metatags to assure some level of IE compatibility.
Here is the code below:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<head>
<title>Google Visualization Demo</title>
<script type="text/javascript" src="http://www.google.com/jsapi">
//call google
</script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['table']}); //load the viz
google.setOnLoadCallback(drawTable);
function drawTable()
{
var data = new google.visualization.DataTable();
data.addColumn('string', 'Opportunity ID');
data.addColumn('string', 'Stage');
<?php
ini_set("soap.wsdl.cache_enabled", "0");
require_once ("./soapclient/SforcePartnerClient.php");
require_once ("./soapclient/SforceHeaderOptions.php");
$username = "insert your username here";
$password = "insert your pw here";
$token = "insert your token here";
$wdsl = "./soapclient/partner.wsdl.xml";
function get_data($username,$password,$token,$wdsl)
{
$client = new SforcePartnerClient();
$client->createConnection($wdsl);
$mylogin = $client->login($username, $password.$token);
$sql = "Select a.Id, a.StageName from Opportunity a where a.StageName like '%LOI%'";
$response = $client->query($sql);
$size = $response->size;
if ($size > 0)
{
$result = $response->records; //dump array results into var
while (!$response->done)
{
$response = $client->queryMore($response->queryLocator);
$result = array_merge($result, $response->records); //merge all batches into one master array
}
}
return $result;
}
$data = get_data($username,$password,$token,$wdsl); //passed user info and other parameters from above into function to estab connection and execute query.
$i = sizeof($data);
$int_y_pos = -1;
$int_y_step_small = 1;
$outputVal = "";
foreach ($data as $r)
{
$int_y_pos += $int_y_step_small;
$outputVal .= "data.setValue(" . $int_y_pos . ", 0,'" . $r->Id . "');"; //string
$outputVal .= "data.setValue(" . $int_y_pos . ", 1,'" . $r->fields->StageName . "');"; //string
}
echo "data.addRows($i);";
echo $outputVal;
?>
var table = new google.visualization.Table(document.getElementById('table'));
table.draw(data, {width: 'automatic', allowHtml: true, showRowNumber: true, page: 'enable', pageSize: 50});
}
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="table"></div>
</body>
</html>
Cheers!
Bookmarks