+ Reply to Thread
Results 1 to 3 of 3

Thread: Salesforce PHP script which lists all Objects and Fields

  1. #1
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15

    Salesforce PHP script which lists all Objects and Fields

    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($etrue) . '</pre>';
        return 
    false;
        exit;
    }
    ?>

  2. #2
    bcolflesh is offline Junior Member
    Join Date
    Mar 2009
    Posts
    1
    Just getting started with Salesforce - this is very helpful - thank you!

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    @bcolflesh !! Thanks for that, I am glad that you are finding the site helpful!!

+ Reply to Thread

LinkBacks (?)

  1. Hits: 2
    02-04-2010, 04:21 AM
  2. Hits: 1
    10-20-2009, 01:44 PM
  3. Hits: 1
    09-28-2009, 05:34 PM
  4. Hits: 1
    08-12-2008, 06:54 PM
  5. Hits: 2
    02-11-2008, 07:11 AM
  6. Hits: 1
    01-15-2008, 10:40 PM
  7. Hits: 1
    01-08-2008, 09:19 PM
  8. Hits: 1
    01-08-2008, 08:04 PM
  9. Hits: 1
    01-04-2008, 05:56 PM
  10. Hits: 1
    01-03-2008, 06:44 AM
  11. Hits: 2
    10-08-2007, 05:42 AM
  12. Hits: 1
    10-07-2007, 07:51 PM
  13. Hits: 1
    10-04-2007, 11:12 AM
  14. Hits: 1
    10-04-2007, 09:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1