+ Start a Discussion
jucuzoglujucuzoglu 

How to list the meta data using SOAP / PHP

Is there a way utilizing the PHP API to read an objects schema and list its meta data.

 

I would like to be able to pass an object name and see all of the field names and their types and even better if the type happens to be a picklist to determine what the available options are.

 

Can someone point me in the right direction or provide a sample?

 

Best Answer chosen by Admin (Salesforce Developers) 
msimondsmsimonds

What about soemthing like this:

 

 

try
{
    //salesforce login and wsdl
    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 />\n";
                
            }
            
             
        }
    }


}
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;
}

 

 

$client would be your connection object to salesforce

 

~Mike

 

All Answers

colingcoling

The describeSObject method is available to do just that. It returns all the fields - with types, picklist values, etc.

 

Once logged in, an example call is:

 

$desc_obj = $sf_connection->describeSObject($sf_object);

 

Regards

 

Colin G

 

msimondsmsimonds

What about soemthing like this:

 

 

try
{
    //salesforce login and wsdl
    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 />\n";
                
            }
            
             
        }
    }


}
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;
}

 

 

$client would be your connection object to salesforce

 

~Mike

 

This was selected as the best answer