Here is a small script that will iterate through all your Salesforce objects and return all the field or column names using PHP 5, the latest PHP toolkit, and the API. I am releasing this so if you want to take a look at all tables and fields, you can. There is nothing special about this script; it's just a handy little tool to view all objects with field names in Salesforce.
This script could help you when you are trying to build a set of scripts that will perform backups for MySQL, Oracle, or postgreSQL.
I hope that it helps people!
~Mike
make sure you check the paths for the Toolkit scripts, wsdl, and your salesforce login information
PHP Code:
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
require_once ('./includes/soapclient/SforcePartnerClient.php');
require_once ('./includes/soapclient/SforceHeaderOptions.php');
// full path name for the create tables file
try {
//salesforce login and wsdl
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "user@email.com";
$password = "password";
//connect to salesforce
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
if (isset($client)) {
// Retrieve all the objects in the organization
$result = $client->describeGlobal();
// Cycle through each object
foreach ($result->types as $objectType) {
// Retrieve the object definition
$resultObject = $client->describeSObject($objectType);
echo "<strong><u>" . $objectType . "</u></strong><br />\n";
// Cycle through each field
foreach ($resultObject->fields as $field) {
echo $field->name . "<br />";
}
echo '<hr />';
}
}
}
catch (exception $e) {
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>' . print_r($e, true) . '</pre>';
return false;
exit;
}
?>
Bookmarks